Skip to content

Prefer declared component instead of same component on imported module #288

Closed
@marcioggs

Description

@marcioggs

Hi!
First of all, thanks for your hard work simplificating my tests and I hope this becomes the de-facto library for Angular tests (as its name almost suggests it)✌

When we provide a service that's already contained in one of the imorted modules, Angular Testing Library gives preference to the one on the providers array. 👍

import { MockProvider} from 'ng-mocks';

await render(ComponentToTest, {
      imports: [ModuleContainingServiceAbc],
      providers: [MockProvider(ServiceAbc)] // Succeeds to use this one
    });

I expected the same to happen on the declarations array, but this is not happening.
Is this the implemented behavior? I'm not sure if I may be doing something wrong.

import { MockComponent } from 'ng-mocks';

await render(ComponentToTest, {
      imports: [ModuleContainingComponentAbc], 
      declarations: [MockComponent(ComponentAbc)] // Fails to use this one
    });

On my specific case, ComponentAbc is not directly declared and exported by ModuleContainingComponentAbc, but by another module that's imported by ModuleContainingComponentAbc.

If you need details on how ng-mocks creates the mocks:
https://ng-mocks.sudo.eu/api/MockProvider
https://ng-mocks.sudo.eu/api/MockComponent

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions