question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MockBuilder: Testing a Router Resolve Service declared in a lazy loading module

See original GitHub issue

Hi @satanTime, When I use MockBuilder to test a Router Resolve Service declared in a lazy loading module. I get this error :

Error: Component XXXComponent is not part of any NgModule or the module has not been imported into your module

I’ve tried to use RouterTestingModule.withRoutes, without success. You can see the error in StackBlitz. The code works fine in production.

angular.json Production : projects -> demo -> architect -> build -> options -> main -> src/main.ts Testing : projects -> demo -> architect -> build -> options -> main -> src/main-testing.ts

Thanks in advance. Best regards. Cyril

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
satanTimecommented, Jul 1, 2020

Based on the provided code MockBuilder should be used like that:

    beforeEach(() => MockBuilder()
        .keep(RouterTestingModule)
        .mock(ActivatedRouteSnapshot, {})
        .mock(RouterStateSnapshot, {})
    );
0reactions
cdupetitcommented, Jul 1, 2020

Thank you very much.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to test declarations of lazy loaded modules in Angular
An example how to mock a lazy loaded module and test its declarations.
Read more >
Unit testing lazy loaded modules routing - angular
Your app-routing.module.ts consists of only two things: the routes and the initialization of the RouterModule . You override both in your test ......
Read more >
Lazy-loading feature modules - Angular
To lazy load Angular modules, use loadChildren (instead of component ) in your AppRoutingModule routes configuration as follows. AppRoutingModule (excerpt)
Read more >
ng-mocks/community - Gitter
hi guys, been trying to use MockBuilder but I struggle on lazy-loaded modules as MockBuilder only accepts one Module as the second argument....
Read more >
How To Use Lazy Loading Routes in Angular | DigitalOcean
Learn how to enable feature modules to be lazy-loaded in Angular, allowing to load the code for some routes to be loaded on-demand....
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