getsaf / shallow-render

Angular testing made easy with shallow rendering and easy mocking. https://getsaf.github.io/shallow-render
MIT License
273 stars 25 forks source link

Standalone Directives not mocked correctly #242

Closed attrobit closed 1 year ago

attrobit commented 1 year ago

When we import an standalone directive, the following error occurs:

Error: "StandaloneDirective" does not have a module def (ɵmod property)

The following unit tests reproduces the bug:

import {Component, Directive, NgModule} from '@angular/core';
import {Shallow} from '../shallow';

@Directive({
  standalone: true,
  selector: 'my-standalone-directive',
})
class MyStandaloneDirective {
}

@Component({
  selector: 'my-component',
  template: '<div my-standalone-directive></div>',
})
class MyComponent {}

@NgModule({
  declarations: [MyComponent],
  // Import the Standalone directive directly into the module
  imports: [MyStandaloneDirective],
})
class ModuleWithStandalone {}

describe('standalone component imported in a module', () => {
  let shallow: Shallow<ModuleWithStandalone>;

  beforeEach(() => {
    shallow = new Shallow(MyComponent, ModuleWithStandalone);
  });

  it('should be mocked', async () => {
    await shallow.render();
  });
});
floisloading commented 1 year ago

We're having the same issue here (using NgOptimizedImage)

attrobit commented 1 year ago

We're having the same issue here (using NgOptimizedImage)

If fixed it and created already a pr.

getsaf commented 1 year ago

Thanks @attrobit for the fix. PR was merged and I just published v15.0.3!