ng-mocks: exclude/keep/replace not working has expected

Hi, it’s me again πŸ™ƒ !

I have a component and a module with StoreModule (NGRX):

@NgModule({
  imports: [
    CommonModule,
    StoreModule.forFeature(myReducer.featureKey, myReducer.reducer),
    EffectsModule.forFeature([MyEffects]),
    MatIconModule,
  ],
  declarations: [MyComponent],
})
export class MyModule {}

When I use provide and provideMockStore for unit test, it works perfectly πŸ‘Œ

MockBuilder(MyComponent, MyModule )
  .provide(provideMockStore({ selectors: [{ selector: mySelectors.selectData, value: [] }]  }));

But when I want to do an integration test (with true StoreModule), i have got an error:

MockBuilder(MyComponent, MyModule )
  .keep(StoreModule.forRoot(reducers))
  .keep(StoreModule.forFeature(myReducer.featureKey, myReducer.reducer));

// OR (same)

MockBuilder(MyComponent, MyModule )
  .keep(StoreModule.forRoot({ [myReducer.featureKey]: myReducer.reducer }));

In fact, the original StoreModule.forFeature is called 😱 . And I’ve got an obscure error (ngrx/ivy/madness/wathever error): TypeError: Cannot destructure property 'strictActionImmutability' of 'undefined' as it is undefined. But the error is not relevant.

If I dont use MyModule in MockBuilder (and mock all my stuff individually) , it’s work :

MockBuilder(MyComponent)
  .mock(MatIconModule)
  .keep(StoreModule.forRoot(reducers))
  .keep(StoreModule.forFeature(myReducer.featureKey, myReducer.reducer));

Like this, I’m sure that StoreModule.forFeature is not called.

I also tried to use exclude before keep, I got the same error:

MockBuilder(MyComponent)
  .exclude(StoreModule)
  .keep(StoreModule.forRoot(reducers))
  .keep(StoreModule.forFeature(myReducer.featureKey, myReducer.reducer));

So I’m not sure how exclude() works.

And I also tried to use replace(StoreModule, StoreModule.forRoot()) but ModuleWithProviser is not alowed.

I think this issue is maybe related to one of my previous issue: #197

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 25 (20 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks for checking! On the weekend I’m releasing it.

Really happy for this fix ! πŸ˜„