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())butModuleWithProviseris 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
- fix(mock-builder): respecting forward-ref and modules with providers #312 — committed to help-me-mom/ng-mocks by satanTime 3 years ago
- Merge pull request #472 from satanTime/issues/312 fix(mock-builder): respecting forward-ref and optional params #312 — committed to help-me-mom/ng-mocks by satanTime 3 years ago
- test: additional case to cover #312 — committed to help-me-mom/ng-mocks by satanTime 3 years ago
Thanks for checking! On the weekend Iβm releasing it.
Really happy for this fix ! π