{ shallow: true } doesn't mock standalone components/directives/pipes
dankerk opened this issue · 3 comments
dankerk commented
Description
If you add the setting { shallow: true } to the createComponentFactory function, it normally mocks all components, directives, pipes that are in the template, which is awesome.
However, it doesn't do this for standalone components, directives, pipes and I think that it should.
Is this something that can be addressed?
Proposed solution
For this setting to work for both "old style" and standalone components/directives/pipes
createComponentFactory({
component: SomeComponent,
shallow: true,
})
Alternatives considered
import { MockComponents } from 'ng-mocks';
createComponentFactory({
component: SomeComponent,
shallow: true,
declarations: [MockComponens(MyStandaloneComponent)],
})
Do you want to create a pull request?
No
denis-manokhin commented
Have the same issue.
Angular version: 15.0.1
Spectator version: 12.2.0
tdesvenain commented
I have the same issue with Angular 16.2, spectator 14.0.0
jhitt25 commented
Until this gets rectified, here is a (hopefully temporary?) solution:
createComponentFactory({
component: StandaloneComponent,
overrideComponents: [
[
StandaloneComponent,
{
remove: { imports: [NestedComponent] },
add: { imports: [MockComponent(NestedComponent)] }
}
]
]
});
This relies on ng-mocks, but that part is easily changed to whatever implementation you wish to use.