Having trouble testing my angular2 app with karma due to a typescript error:
/my/path/node_modules/angular2/src/testing/matchers.d.ts
Error:(4, 37) TS2503: Cannot find namespace 'jasmine'.
All NPM Modules are installed and the typescript compiler is functioning correctly. So, what could be causing this issue?
This is how myservice.serviceSpec.ts looks like:
import {it, describe, expect, beforeEach, inject} from
'angular2/testing';
import {myService} from "../app/myservice.service";
describe('Tests', () => {
it('should be true', () => {
expect(true).toBe(true);
});
});
Here's what my package.json contains:
{
"name": "myapp",
"version": "0.1.0",
"dependencies": {
"angular2": "^2.0.0-beta.2",
"es6-promise": "^3.0.2",
"es6-shim": "^0.33.13",
"reflect-metadata": "^0.1.2",
"rxjs": "^5.0.0-beta.0",
"systemjs": "^0.19.17",
"zone.js": "^0.5.10"
},
"devDependencies": {
"jasmine-core": "^2.4.1",
"karma": "^0.13.19",
"karma-chrome-launcher": "^0.2.2",
"karma-coverage": "^0.5.3",
"karma-jasmine": "^0.3.7",
"remap-istanbul": "^0.5.1"
}
}
This is the content of my tsconfig.json file:
{
"compilerOptions": {
"target": "ES5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true
},
"exclude": [
"node_modules"
]
}
My karma.conf.js configuration:
// Karma configuration
// Generated on Wed Feb 10 2016 09:56:19 GMT+0100 (CET)
module.exports = function (config) {
config.set ({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'node_modules/systemjs/dist/system.src.js',
'node_modules/angular2/bundles/http.dev.js',
'test/karma_test_shim.js',
'test/myservice.serviceSpec.js',
{pattern: 'app/**/*.js', included: false, watched: true},
{pattern: 'test/**/*Spec.js', included: false, watched: true}
],
// other configurations...
})
}
This is my karma_test-shim.js script:
// JavaScript code for karma_test-shim.js...