I am using jQuery in my angular 5 app which works perfectly but I have an issue with karma tests.
import { ElementRef } from '@angular/core';
declare var jQuery: any;
export class Item {
constructor(private element: ElementRef) {
this.init();
}
private init() {
this.$item = jQuery(this.element.nativeElement);
...
error
ReferenceError: jQuery is not defined.
package.json
"dependencies": {
"jquery": "3.1.1"
}
I have added jquery to my karma.conf but that didn't help.
files: [
'node_modules/core-js/client/shim.js',
'node_modules/systemjs/dist/system.src.js',
'node_modules/zone.js/dist/zone.js',
'node_modules/zone.js/dist/proxy.js',
'node_modules/zone.js/dist/sync-test.js',
'node_modules/zone.js/dist/jasmine-patch.js',
'node_modules/zone.js/dist/async-test.js',
'node_modules/zone.js/dist/fake-async-test.js',
'node_modules/tslib/tslib.js',
'node_modules/jquery/dist/jquery.js',
{pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
{pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false },
{pattern: '../karma-test-shim.js', included: true, watched: true},
{pattern: 'node_modules/@angular/**/*.js', included: false, watched: false},
{pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: false},
{pattern: 'node_modules/@ng-idle/core/bundles/core.umd.js', included: false, watched: false},
{pattern: 'node_modules/bowser/bowser.js', included: false, watched: false},
{pattern: 'node_modules/bootstrap/dist/js/bootstrap.js', included: false, watched: false},
{pattern: 'node_modules/tslib/tslib.js', included: false, watched: false},
{pattern: 'node_modules/jquery/dist/jquery.js', included: false, watched: false}
],
proxies: {
"/node_modules/": "../../node_modules/"
},
autoWatch: true,
browsers: ['PhantomJS', 'Chrome', 'HeadlessChrome'],
singleRun: false
});
};
can you someone please help?
Thanks in advance.