@@ -31,18 +31,31 @@ export class MatCommonModule {
31
31
/** Whether we've done the global sanity checks (e.g. a theme is loaded, there is a doctype). */
32
32
private _hasDoneGlobalChecks = false ;
33
33
34
+ /** Whether we've already checked for HammerJs availability. */
35
+ private _hasCheckedHammer = false ;
36
+
34
37
/** Reference to the global `document` object. */
35
38
private _document = typeof document === 'object' && document ? document : null ;
36
39
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 ( ) ;
41
44
this . _hasDoneGlobalChecks = true ;
42
45
}
43
46
}
44
47
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 {
46
59
if ( this . _document && ! this . _document . doctype ) {
47
60
console . warn (
48
61
'Current document does not have a doctype. This may cause ' +
@@ -51,7 +64,7 @@ export class MatCommonModule {
51
64
}
52
65
}
53
66
54
- private _checkTheme ( ) : void {
67
+ private _checkThemeIsPresent ( ) : void {
55
68
if ( this . _document && typeof getComputedStyle === 'function' ) {
56
69
const testElement = this . _document . createElement ( 'div' ) ;
57
70
@@ -74,4 +87,13 @@ export class MatCommonModule {
74
87
this . _document . body . removeChild ( testElement ) ;
75
88
}
76
89
}
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
+ }
77
99
}
0 commit comments