Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Reference Error : $ is not defined Angular6 unit test

I am working on writing unit test using karma, jasmine, mocha etc. I am having one module imported in application which have jQuery as dependency but I am getting error while running test case i.e

ReferenceError: $ is not defined

I have added jQuery reference in angular.json as .

"test": {
  "builder": "@angular-devkit/build-angular:karma",
  "options": {        
    "styles": [],
    "scripts": [
      "node_modules/jquery/dist/jquery.min.js"
    ],
    "assets": [
      //Assers
    ]
  }

I also tried adding jQuery reference in tsconfig.spec.json as

"files": [
  "../../node_modules/jquery/dist/jquery.min.js",
  "src/test.ts",
  "src/polyfills.ts"   
],

Comments