-
-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
exclude/keep/replace not working has expected #312
Comments
Hi, this is a complicated topic. The original idea for such cases is to mock a module which imports Something like that Then Anyway I'll investigate the cases and try to fix related issues. |
I was able to reproduce the issue. Working on a fix for it. |
Could you check whether the next config works with .keep(StoreRootModule)
.keep(StoreFeatureModule)
.keep(EffectsRootModule)
.keep(EffectsFeatureModule) |
Hm.... actually it works for me correctly... .keep(StoreModule.forRoot({}))
.keep(StoreModule.forFeature(myReducer.featureKey, myReducer.reducer))
.keep(EffectsModule.forRoot())
.keep(EffectsModule.forFeature())) doesn't show any error. Could you try the same and let me know if it works? |
Could you also check this PR: https://github.com/ike18t/ng-mocks/pull/472/files? Maybe I something missed in the tests. |
Sorry for the late reply. + Please pay attention that `MyModule` or its imports should import `.forRoot` and `.forFeature`,
+ otherwise we need to call [`.keep`](../../api/MockBuilder.md#keep) as usually: The two modules I'm testing don't have a If I add |
Aha, for a lazy loaded module, you need the context from the module which loads the lazy loaded module. so it should be something like MockBuilder(Component, [LazyModule, AppModule]).keep(....) I think, it is a good point to be clarified in the docs. Would it work for you, or you would like to see it differently? |
Indeed, I never thought of mentioning to you that it was lazy-loading. Besides, even if it's not a lazy-loaded module, there is always, more or less, one or more context modules (parent module and the AppModule). Your solution is cool. But it may make the test context bigger if the AppModule is big (which is often the case). It would be nice to be able to provide only what is missing (in my case I only need Like:
or
|
Aha, got it. Then I would say the first one wouldn't work, because and something like So in your case it should be something like MockBuilder(Component, LazyModule).keep(StoreModule.forRoot()).keep(StoreFeatureModule); looks a bit ugly, but it should do the string. |
We'll have to check that it works well. Because with the |
Is it the same as |
Aha, I was able to get This is because this is an optional token which hasn't been provided, but Adding a fix to skip optional dependencies if they are not provided. |
Well done! I can't wait to test this ! 👍 |
Here you go! This is the way: |
Yeah !! It's work perfectly. Nice job !! |
Thanks for checking! On the weekend I'm releasing it. |
Really happy for this fix ! :D |
fix(mock-builder): respecting forward-ref and optional params #312
v11.11.0 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. |
After upgrading to The I'm exactly in the same context as kekel87 (lazy loaded module):
|
Hi @Dji75, Thanks for the info. Could you provide a min repo / example? |
Hi @Dji75, I've added one more test case: https://github.com/ike18t/ng-mocks/pull/530/files, but it works well. I think, the issue you pointed belongs to a missed reducer in In such a case, MockBuilder(MyComponent, [LazyModule, AppModule])
.keep(FormsModule)
.keep(ReactiveFormsModule)
.keep(StoreRootModule)
.keep(StoreFeatureModule) Then all reducers will be present in the context of |
v11.11.2 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. |
I've finally go ahead on this topic :) Thanks for the provided code but I still have some issues. The first one is that my The second one was due to BrowserAnimationsModule (in AppModule) which I have to replace by NoopAnimationsModule ( The last one is the tricky one ;) With those "reset", all tests are successful, else some of them fail (depending on seed). Any idea what happens here ? |
Hi @Dji75,
|
I finally found why my tests runs not using initial (empty) initial state, this was because the spy on my metaReducer util was not taken into account, so I got previous value from sessionStorage which failed some tests :( Here is the declaration in StoreModule.forRoot({}, { metaReducers: [ReducerUtils.storePersist], runtimeChecks: environment.storeRuntimeChecks }), Here is how I set spy (using jasmine), prior to spyOn(ReducerUtils, 'storePersist').and.callFake((v) => v); Maybe it can help you to see util's declaration ;) export abstract class ReducerUtils {
static storePersist(reducer: ActionReducer<object>): ActionReducer<object> {
... If I add some logs in this util, I can see them in console 👎 Moreover, I see another problem using you asked me before how I spy on store, here it is: describe('integration', () => {
let store: Store;
...
const initTestBed = () => {
...
return MockBuilder(MyComponent, [MyModule, AppModule])
.keep(StoreRootModule)
.keep(StoreFeatureModule)
.keep(StoreDevtoolsModule)
.keep(NoopAnimationsModule)
.keep(FormsModule)
.keep(ReactiveFormsModule);
};
beforeEach(initTestBed);
beforeEach(() => {
fixture = MockRender(MyComponent);
store = TestBed.inject(Store);
spyOn(store, 'dispatch').and.callThrough();
fixture.detectChanges();
}); |
Hi, it's me again 🙃 !
I have a component and a module with
StoreModule
(NGRX):When I use
provide
andprovideMockStore
for unit test, it works perfectly 👌But when I want to do an integration test (with true
StoreModule
), i have got an error: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 :Like this, I'm sure that
StoreModule.forFeature
is not called.I also tried to use
exclude
beforekeep
, I got the same error:So I'm not sure how
exclude()
works.I think this issue is maybe related to one of my previous issue: #197
The text was updated successfully, but these errors were encountered: