How can I suppress "WARN: 'Could not find HammerJS." on each text execution?

When executing tests, each test logs the following:

WARN: 'Could not find HammerJS. Certain Angular Material components may not work correctly.'

From from Angular Material Getting Started Guide:

Some components (md-slide-toggle, md-slider, mdTooltip) rely on HammerJS for gestures. In order to get the full feature-set of these components, HammerJS must be loaded into the application.

Based on that, my conclusion is that I don't need HammerJS installed as I'm not specifically using the Angular Material components that require it. If you don't need it, don't add it!

But whilst executing 1000+ tests, having that warning print out each time really isn't helpful and so I want to get rid of it or have it print once only.


The following solution will:

  1. Warn about the lack of HammerJS once only.
  2. Print an error to the console if you ever end up using the new Hammer() constructor in the future.
  3. Not require you to call enableProdMode() within your test environment so you can continue to benefit from the additional error checking that double change detection provides.

Add the following beforeAll function to your test bundle:

beforeAll(function() {
    if (!window.hasOwnProperty('Hammer')) {
        window['Hammer'] = function() {
                'HammerJS is not installed. If you\'re now using Angular Material components that require it, please "npm i hammerjs"'
        console.warn('Could not find HammerJS. Certain Angular Material components may not work correctly.');


 ? hammer.js exhibits pinch lag when changing pinch direction (tested on Android)
 ? angular2 and typescript error
 ? Angular2: hammerjs is not found
 ? Turn off Hammer JS events in Angular 2 to allow scrolling
 ? Angular Dragula and ng-repeat $index
 ? Dragula Drag only wanted elements
 ? angular2 Dragula css cursor grab/grabbing not working
 ? ng2-dragula group items in div
 ? Adding Dragular to Angular2 Application: document is not defined
 ? AOT error: require is not defined (caused by ng2-dragula library)