-
-
Notifications
You must be signed in to change notification settings - Fork 85
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
Mocking Angular Material modules do not work #50
Comments
Hi @sinedied, thanks for for the report. Could you create simple project and share its code to demonstrate the error? |
Sure! Is a stackblitz project ok for you? |
it's perfect |
It was hard to reproduce, but here it is: https://stackblitz.com/edit/ng-mock-material-issue?file=src%2Fapp%2Fshared.module.mock.ts Seems it's somehow related to the |
Thanks I'll check next days and prepare fix. |
I have pinpointed the issue to the |
This is an issue with auto-mocking the I would recommend enhancing As a hack, you can re-provide a dummy config on top of your mocked modules like so: @NgModule({
imports: [
// ...
...MaterialModulesMocks
],
/* This is a hack.. You really want to avoid doing this at the MockModule level */
providers: [
{provide: HAMMER_GESTURE_CONFIG, useValue: {events: []}}
],
// ...
}) Here's your first StackBlitz with this hack applied: |
Wanted to follow up that @satanTime has enhancements planned for See his comment about it on another issue. |
Hi guys, sorry for the long delay, work, you know. Checking the thing. |
So, I was trying to reproduce the issue with angular 9, but no luck. The stackblitz.com sample is too old and I can't run it easily on node 12, it requires node 10. |
Should be fixed by #80 |
I'm trying to mock Angular Material modules to avoid using NO_ERRORS_SCHEMA when doing shallow components testing, but it's not working for me.
At first, I tried mocking my
material.module.ts
which is just a module that re-exports all material individual modules, and it's not working at all as I get "unknown element <mat-card" and such.Then I tried mocking all material modules individually with
modules.map((module: any) => MockModule(module));
and use that in myshared.module.mock.ts
, a module that I import in all my unit tests for convenience. This module imports & exports the mocked material modules.This works better as I don't get "unknown element" errors, but this time I'm stuck on this error:
Obviously, this error is not there when I use the real material modules.
Do you have any idea or workaround for this?
Thanks!
The text was updated successfully, but these errors were encountered: