@@ -31,18 +31,31 @@ export class MatCommonModule {
3131 /** Whether we've done the global sanity checks (e.g. a theme is loaded, there is a doctype). */
3232 private _hasDoneGlobalChecks = false ;
3333
34+ /** Whether we've already checked for HammerJs availability. */
35+ private _hasCheckedHammer = false ;
36+
3437 /** Reference to the global `document` object. */
3538 private _document = typeof document === 'object' && document ? document : null ;
3639
37- constructor ( @Optional ( ) @Inject ( MATERIAL_SANITY_CHECKS ) sanityChecksEnabled : boolean ) {
38- if ( sanityChecksEnabled && ! this . _hasDoneGlobalChecks && isDevMode ( ) ) {
39- this . _checkDoctype ( ) ;
40- this . _checkTheme ( ) ;
40+ constructor ( @Optional ( ) @Inject ( MATERIAL_SANITY_CHECKS ) private _sanityChecksEnabled : boolean ) {
41+ if ( this . _areChecksEnabled ( ) && ! this . _hasDoneGlobalChecks ) {
42+ this . _checkDoctypeIsDefined ( ) ;
43+ this . _checkThemeIsPresent ( ) ;
4144 this . _hasDoneGlobalChecks = true ;
4245 }
4346 }
4447
45- private _checkDoctype ( ) : void {
48+ /** Whether any sanity checks are enabled */
49+ private _areChecksEnabled ( ) : boolean {
50+ return this . _sanityChecksEnabled && isDevMode ( ) && ! this . _isTestEnv ( ) ;
51+ }
52+
53+ /** Whether the code is running in tests. */
54+ private _isTestEnv ( ) {
55+ return window [ '__karma__' ] || window [ 'jasmine' ] ;
56+ }
57+
58+ private _checkDoctypeIsDefined ( ) : void {
4659 if ( this . _document && ! this . _document . doctype ) {
4760 console . warn (
4861 'Current document does not have a doctype. This may cause ' +
@@ -51,7 +64,7 @@ export class MatCommonModule {
5164 }
5265 }
5366
54- private _checkTheme ( ) : void {
67+ private _checkThemeIsPresent ( ) : void {
5568 if ( this . _document && typeof getComputedStyle === 'function' ) {
5669 const testElement = this . _document . createElement ( 'div' ) ;
5770
@@ -74,4 +87,13 @@ export class MatCommonModule {
7487 this . _document . body . removeChild ( testElement ) ;
7588 }
7689 }
90+
91+ /** Checks whether HammerJS is available. */
92+ _checkHammerIsAvailable ( ) : void {
93+ if ( this . _areChecksEnabled ( ) && ! this . _hasCheckedHammer && ! window [ 'Hammer' ] ) {
94+ console . warn (
95+ 'Could not find HammerJS. Certain Angular Material components may not work correctly.' ) ;
96+ }
97+ this . _hasCheckedHammer = true ;
98+ }
7799}
0 commit comments