-
-
Notifications
You must be signed in to change notification settings - Fork 86
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
Clarification re: Type is part of the declaration of 2 modules #435
Comments
Hi, thanks for the report. yeah, a very good case :) Thanks! It will be fixed with the next release. |
Ah, right. That explains it. It probably also explains why I see the default implemented behavior of Is there anything I can do to work around this for the time being? I don't see any clear points where this would happen in |
The idea around skipping About a work around.... A good question :) I think you could try |
It works, sort of, except it's going to be a bit of a pain to set up all the But then I've found the source to my issues here, so I'm gonna go ahead and close this issue. I'll revisit once the next release is out to see if we can do things differently at that point but for now this gets me further - thanks a lot for the help! |
Nice. Btw, please keep the issue open, it works like a reminder for me to solve it when I have time. It will be closed during a release process of the next version. |
So, actually Looking for a solution how to inject MockOfCommonModule into |
Hi @tanordheim, could you verify whether this version works for you needs? Thanks in advance! |
For my usecase, this worked. The test case below yielded the expected "Type NgClass is part of the declarations of 2 modules" error on the latest release, and passed successfully with the version you attached. @Component({
template: '<p>{{ testDate | date:"short" }}</p>',
})
class TestComponent {
testDate = new Date();
}
describe('DatePipe mock', () => {
beforeEach(() => {
return MockBuilder(TestComponent, SharedModule)
.mock(DatePipe, (v: any) => 'mocked:' + v);
});
it('should use mocked date pipe', () => {
const fixture = MockRender(TestComponent);
expect(fixture.point.nativeElement.textContent).toContain('mocked');
});
}); Thanks so much for the update! |
Thanks for the feedback! On the upcoming weekend, I'll release a new version with the fix. |
fix(mock-builder): overrides mock modules for platform #435
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. |
Hi, and thanks for a great library! I'm currently evaluating this for one of our Angular applications and I've come across one of the issues documented here where I have the following situation:
A
and moduleB
both importCommonModule
from@angular/common
.B
depends on moduleA
.B
where I need to mock out something fromCommonModule
explicitly.I have set up a StackBlitz showcasing what I try to do here: https://stackblitz.com/edit/angular-ivy-7cnyfm?file=src/app/feature/sample.component.spec.ts
I basically have:
SharedModule
which importsCommonModule
.FeatureModule
which importsSharedModule
andCommonModule
SampleComponent
inSharedModule
which takes a date input and passes it to the AngularDatePipe
.I set this up according to my understanding of the docs I linked earlier like this:
This fails with the following error:
...and then repeated for more or less everything else in
CommonModule
.Am I misunderstanding the docs here? I'd be happy to help clarify if I understood what the problem was, but as far as I'm able to tell this should be how things are intended to work.
This error also occurs if I stop including
SharedModule
in myFeatureModule
and set the tests up like this, leading me to believe this isn't the same case as in the documentation:Setting it up like in the documentation with
.keep(FeatureModule)
and.mock(CommonModule)
also yields the same results.The text was updated successfully, but these errors were encountered: