1

When writing unit tests for a component that uses a Material Slider and depends on HammerJS for it, I'm seeing this error WARN LOG: 'The "slide" event cannot be bound because Hammer.JS is not loaded and no custom loader has been specified.'

I've made the import and added the provider for the dependency:

import { BrowserModule, HAMMER_GESTURE_CONFIG } from '@angular/platform-browser';

But still I get the same error on every test. How do I resolve this dependency?

1 Answer 1

2

Ok, so this turned out to be an obvious fix. Just leaving this up in case it's useful to anyone else.

Simply ensure you import the dependency itself in your unit test. In this case, that's hammerjs and not the providers you configure in your app module to use it within your angular material components.

So, inside your spec test file:

import 'hammerjs';

That's it. This assumes it's installed in your application and appears in your package.json, which it almost certainly does if it's used by the component.

Not the answer you're looking for? Browse other questions tagged or ask your own question.