components: bug: Sanity checks run in test environement

As I explained in comment on PR ( https://github.com/angular/components/pull/23289 ) I have a lot of warnings coming from angular material sanity checks during my unit test runs, what makes the output unreadable. @jelbourn advised me to open an issue because sanity checks should not run in test environment.

Thanks for your help !

Steps to reproduce:

  1. Fork https://github.com/eweap/angular-material-warn
  2. Run yarn install then run test with yarn nx test ui to run the test for the ui lib (its a nrwl/nx workspace)

Expected Behavior

What behavior were you expecting to see? No warning should be display during the test run

Actual Behavior

What behavior did you actually see? A warning is displayed:

console.warn
      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

      at MatCommonModule.Object.<anonymous>.MatCommonModule._checkThemeIsPresent (../../../src/material/core/common-behaviors/common-module.ts:144:15)
      at new MatCommonModule (../../../src/material/core/common-behaviors/common-module.ts:81:12)
      at Object.MatCommonModule_Factory [as factory] (../../node_modules/@angular/material/bundles/material-core.umd.js:189:69)
      at R3Injector.Object.<anonymous>.R3Injector.hydrate (../../../packages/core/src/di/r3_injector.ts:416:29)
      at R3Injector.Object.<anonymous>.R3Injector.get (../../../packages/core/src/di/r3_injector.ts:211:23)
      at ../../../packages/core/src/di/r3_injector.ts:247:51
          at Set.forEach (<anonymous>)
      at R3Injector.Object.<anonymous>.R3Injector._resolveInjectorDefTypes (../../../packages/core/src/di/r3_injector.ts:247:27)

Environment

  • Angular: 12.2.1
  • CDK/Material: 12.2.1
  • Operating System (e.g. Windows, macOS, Ubuntu): Ubuntu

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 22 (9 by maintainers)

Commits related to this issue

Most upvoted comments

@crisbeto it looks like we should update our test env check to look for jest

fingers crossed this makes it into 13 (also, hurrah for 13 🎉)

I tried a sample Jest project and could confirm that it doesn’t get published to global. I’ve submitted #23722 to hopefully address it once and for all.

Great, thank you for testing! I’ll submit a fix for it later today.

Hmm, I updated to 12.2.9 this morning, and I’m still seeing these in the logs when running jest.

console.warn
      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

      at MatCommonModule.Object.<anonymous>.MatCommonModule._checkThemeIsPresent (../../../src/material/core/common-behaviors/common-module.ts:133:15)
      at new MatCommonModule (../../../src/material/core/common-behaviors/common-module.ts:82:12)
      at Object.MatCommonModule_Factory [as factory] (../../node_modules/@angular/material/bundles/material-core.umd.js:179:69)
      at R3Injector.Object.<anonymous>.R3Injector.hydrate (../../../packages/core/src/di/r3_injector.ts:416:29)
      at R3Injector.Object.<anonymous>.R3Injector.get (../../../packages/core/src/di/r3_injector.ts:211:23)
      at ../../../packages/core/src/di/r3_injector.ts:247:51
          at Set.forEach (<anonymous>)
      at R3Injector.Object.<anonymous>.R3Injector._resolveInjectorDefTypes (../../../packages/core/src/di/r3_injector.ts:247:27)

@wagnermaciel Hi, I’ve just tried the new release and the bug is still here ! Take a look at the reproduction repo that I have updated to 12.2.7 I think this issue should be re-open

Thanks