Cannot read property 'ngModule' of undefined

See original GitHub issue

I have the following setup: I like to test the ProfileOverviewComponent and create mocks for all declarables in its module, which is the ProfileOverviewLazyLoadedModule.

 beforeEach(async(() => {
        const metadata = ngMocks.guts(ProfileOverviewComponent, ProfileOverviewLazyLoadedModule);
        metadata.providers.push({ provide: Store, useValue: storeMock });
        TestBed.configureTestingModule(metadata).compileComponents();
    }));

But now the test shows the following error: Failed: Cannot read property ‘ngModule’ of undefined image

The ProfileOverviewLazyLoadedModule imports around 15 other modules, which have declarables on their own (that need to be mocked in this case). I think some module lookup t read the metadata of the module might be incorrect?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
satanTimecommented, Dec 9, 2020

@wvankoppen, thanks, glad to hear! I need to cover the fix with tests and will release it on the weekend.

0reactions
satanTimecommented, Dec 10, 2020

v11.2.3 has been released and contains a fix for the issue. Feel free to reopen the issue or to submit a new one if you meet any problems.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'ngModule' of undefined - Stack Overflow
The error occurs when the value is undefined, so we can put here a conditional breakpoint with the condition !value , what will...
Read more >
Cannot read property 'ngModule' of undefined · Issue #39573 ...
I believe it's not possible to error for circular deps; they aren't always a problem. It may be possible for the runtime JIT...
Read more >
How to fix "Cannot read properties of undefined (reading ...
I don't have a good answer for this one... I want to iterate the app works perfectly, this is only a problem when...
Read more >
NgModule - Angular
A name or path that uniquely identifies this NgModule in getNgModuleById . If left undefined , the NgModule is not registered with getNgModuleById...
Read more >
ngmodel cannot read properties of undefined - You.com
Here's an example of a JavaScript TypeError: Cannot read property of undefined thrown when a property is attempted to be read on an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found