Skip to content

Get rid of "Could not find angular material core theme" warning when using with angular-material #83

Closed
@damoonrashidi

Description

@damoonrashidi

When running tests with jest + jest-preset-angular in a non angular-cli app you get a

console.warn node_modules/@angular/material/bundles/material.umd.js:191
      Could not find Angular Material core theme. Most Material components may not work as expected. For more info refer to the theming guide: https://material.angular.io/guide/theming

warning for each of your components that contain an angular material component. Since there is no way of actually loading the theme in a non angular-cli app test you have to disable the warning by injecting some css in the JSDOM page to trick angular material that the page has loaded the css.

This can be done by modifying the setupJest.ts file to look like this

declare var global: any;

const style = global['document'].createElement('style');
style.innerHTML = `
  .mat-theme-loaded-marker {
    display: none;
}`;
global['document'].head.appendChild(style);

Maybe this can be added to the README.md? Unless of course I'm mistaken and there is an actual "proper" way of doing it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions