Skip to content
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

Bug: "Nested" module replacement not working as expected #4486

Open
twjacobsen opened this issue Dec 8, 2022 · 7 comments · May be fixed by #4501
Open

Bug: "Nested" module replacement not working as expected #4486

twjacobsen opened this issue Dec 8, 2022 · 7 comments · May be fixed by #4501
Assignees
Labels
bug Something isn't working

Comments

@twjacobsen
Copy link

Description of the bug

When using MockBuilder to replace a module import with a "testing module", that in turn imports some other "testing module" is not working as expected. The declarations of the sub-testing-module is not made available in my tests

An example of the bug

Link: https://stackblitz.com/edit/github-fvnrfv?file=src/test.spec.ts

Expected vs actual behavior

Expected behaviour: The component in the test renders as name: sandboxt one testing two

Actual behaviour: The component in the test renders as name: sandboxt one two, indicating the nested module declarations are not used

Brief of the code structure:
Component imports Sub1Module which declares Component1 and imports Sub2Module. Sub2Module declares Component2.

In test, Sub1Module is replaced with Sub1TestingModule, which declares Component1 but imports Sub2TestingModule. Sub2TestingModule declares ComponentTesting2.

The selectors of Component2 and ComponentTesting2 are identical.

We've been using this pattern for regular non-standalone component testing, where we usually provide all module imports manually to the test. We've started using MockBuilder for standalone component testing, since it's very convenient - but this one issue is a pretty big deal to us :(

@twjacobsen twjacobsen added the bug Something isn't working label Dec 8, 2022
@satanTime
Copy link
Member

satanTime commented Dec 9, 2022

@twjacobsen
Copy link
Author

Thanks for "correcting" the test.

I'm having a hard time reading in the docs, if it's possible to replace a submodule using MockBuilder. Ie. instead of creating Sub1TestingModule in my example, would it be possible to do MockBuilder().keep(Sub1Module).replace(Sub2Module, Sub2TestingModule)? It does not look as if it's possible.

@satanTime
Copy link
Member

Hi @twjacobsen,

what you do is expected and is exactly how the .replace works.
However, it turned out to be a bug in angular itself.

I've submitted a bug here: angular/angular#48432

satanTime added a commit to satanTime/ng-mocks that referenced this issue Dec 10, 2022
satanTime added a commit to satanTime/ng-mocks that referenced this issue Dec 10, 2022
@satanTime satanTime linked a pull request Dec 10, 2022 that will close this issue
satanTime added a commit to satanTime/ng-mocks that referenced this issue Dec 10, 2022
satanTime added a commit to satanTime/ng-mocks that referenced this issue Dec 11, 2022
@twjacobsen
Copy link
Author

Thanks a lot for finding that. I'll follow these issues closely :)

@satanTime
Copy link
Member

Hey @twjacobsen,

Thanks for the update.
Stay in touch then!

satanTime added a commit to satanTime/ng-mocks that referenced this issue Jan 15, 2023
satanTime added a commit to satanTime/ng-mocks that referenced this issue Jan 22, 2023
satanTime added a commit to satanTime/ng-mocks that referenced this issue Jan 29, 2023
satanTime added a commit to satanTime/ng-mocks that referenced this issue Apr 15, 2023
@dtomaszewski
Copy link

dtomaszewski commented Aug 11, 2023

hi @satanTime I see there is test PR, any chance for some progress ?

@satanTime
Copy link
Member

Hi @dtomaszewski, it's still blocked on Angular's side: angular/angular#48432

satanTime added a commit to satanTime/ng-mocks that referenced this issue Nov 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants