help-me-mom / ng-mocks

Angular testing library for mocking components, directives, pipes, services and facilitating TestBed setup
https://www.npmjs.com/package/ng-mocks
MIT License
1.07k stars 81 forks source link

Bug: fixture.getDeferBlocks() returns no defer blocks if we want to use any ng-mocks mock inside the test #7742

Open edekovacsgalambos opened 11 months ago

edekovacsgalambos commented 11 months ago

Description of the bug

There a problem when trying to use ng-mocks in test which would like to use tools for new @defer block testing, the problem is: fixture.getDeferBlocks(); will return no defer blocks if we have any ng-mocks mock inside the test.

An example of the bug

Here is minimalistic example to reproduce

angular-jest-defer-ng-mock.zip

check test-defer.component.spec.ts in the example project

if we comment out .overrideComponent(...) from component ts file and <test-child-defer /> line from template, the test will pass.

Expected vs actual behavior

Mocking components with ng-mock has no effect on fixture.getDeferBlocks() functioning, it will return defer block correctly.

csaszika commented 10 months ago

While we are waiting for the solution, this is my workaround:

.overrideComponent(TestDeferChildComponent, {
        set: {
          template: '<div>TestDeferChildComponent</div>',
        },
      })

The inputs and other meta configuration will be the same. Injected services into child component will be resolved by TestBed. Not perfect because MockComponent(TestDeferChildComponent) would be nicer and shorter, but for now, it works. However it won't hide dependencies of the child.

a-audusseau commented 4 months ago

Hi! Any news on this? I have exactly the same issue and I can't use the workaround as I need to prevent the child component to pull all its dependencies.

csaszika commented 3 months ago

@satanTime Can you give us an update, will it be investigated/fixed? what do you think?

Ozmerg commented 1 month ago

Hello there, I'm facing the same issue. Is there any update on this?