4

I'm trying to install the jasmine plugin "jasmine-ajax" in an angular-cli project. The instructions seem pretty standard, but I keeping getting this error:

"ERROR in src/app/app.component.spec.ts(8,13): error TS2339: Property 'Ajax' does not exist on type 'typeof jasmine'."

I keep seeing an error on jasmine.Ajax.install()

In my karma.conf.js file, I have this:

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine-ajax', 'jasmine', '@angular/cli'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular/cli/plugins/karma'),
      require('karma-jasmine-ajax')
    ],
    client:{
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      reports: [ 'html', 'lcovonly' ],
      fixWebpackSourcePaths: true
    },
    angularCli: {
      environment: 'dev'
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false
  });
};

I also tried to add the plugin using the helpers section in the jasmine.json. This is what my jasmine.json file looks like:

{
    "spec_dir": "spec",
    "spec_files": [
        "**/*[sS]pec.js"
    ],
    "helpers": [
        "helpers/**/*.js",
        "../../../node_modules/jasmine-ajax/lib/mock-ajax.js"
    ],
    "stopSpecOnExpectationFailure": false,
    "random": true
}

Has anyone installed the jasmine-ajax plugin successfully lately?

Could it be the version of jasmine-ajax?

tuuk79
  • 51
  • 5
  • I've found a typing in for it: ```npm i @types/jasmine-ajax ``` But couldn't use it with my Angular project. If I could make it work, I'll post an answer. Hope this helps anyway. – Anton Nov 07 '18 at 15:09

1 Answers1

0

You are on the rigth path. You need to install the type definitions for TypeScript:

npm i @types/jasmine-ajax

and include them in your e2e/tsconfig.e2e.json:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/e2e",
    "baseUrl": "./",
    "module": "commonjs",
    "target": "es5",
    "types": [
      "jasmine",
      "jasminewd2",
      "node",
      "jasmine-ajax"
    ]
  }
}
Sebastian Viereck
  • 5,455
  • 53
  • 53