Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{ shallow: true } doesn't mock standalone components/directives/pipes #628

Open
dankerk opened this issue Sep 19, 2023 · 3 comments
Open

Comments

@dankerk
Copy link

dankerk commented Sep 19, 2023

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
Copy link

Have the same issue.

Angular version: 15.0.1
Spectator version: 12.2.0

@tdesvenain
Copy link

I have the same issue with Angular 16.2, spectator 14.0.0

@jhitt25
Copy link

jhitt25 commented Jan 12, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants