Platform: Unit Tests Breaking : Uncaught TypeError: Cannot read property 'entities' of undefined

Created on 8 Feb 2019  路  11Comments  路  Source: ngrx/platform

I am getting this error randomly on different unit tests. It breaks on a different unit test each time tests are ran. However, sometimes all tests pass successfully.

Angular Version: 7.2.4
@ngrx Version: 7.0.0

Needs Reproduction Store

Most helpful comment

I think what ultimately fixes the issue is destroying the feature after create component

  beforeEach(() => {
    fixture = TestBed.createComponent(ComponentNameComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });
  afterEach(() => {
    fixture.destroy();
  });

All 11 comments

I think what ultimately fixes the issue is destroying the feature after create component

  beforeEach(() => {
    fixture = TestBed.createComponent(ComponentNameComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });
  afterEach(() => {
    fixture.destroy();
  });

It's quite annoying to have to add the fixture.destroy() in each component I'm testing. I've never had to do this for anything else as a fresh instance is always created in each beforeEach. Why is this necessary when using provideMockStore()?

Can this issue please be re-opened @cport1.

I reopened the issue.

Really annoying it's breaking our verification system, even with fixture.destroy() it randomly fail. We have git pre hooks that run test on push ...

Really annoying it's breaking our verification system, even with fixture.destroy() it randomly fail. We have git pre hooks that run test on push ...

Does it fail on a different component each run?

Does anyone have a small reproduction of this behavior?

Closing this in favor of #2044, because I think it's a duplicate.
If it's not the case feel free to create a reproduction and create a new issue.

happens for me as well, I tried to add afterEach(() => { fixture.destroy(); }); in one test and it helped for more tests to pass, but then another random test had failed...

i got the same issue

facing the same issue,

An error was thrown in afterAll error properties: Object({ longStack: 'TypeError: Cannot convert undefined or null to object

I had a similar error:
An error was thrown in afterAll error properties: Object({ longStack: 'TypeError: Cannot ...
and it turned out I just forgot to mock one selector, and the value which it was supposed to emit wasn't being checked in the given component tests, therefore sometimes everything would pass and sometimes throw an error.

Was this page helpful?
0 / 5 - 0 ratings