I am currently working on writing a unit test for my Angular 1 application using JSPM with Karma and Jasmine.
Below is a snippet of my Karma configuration (jspm section) :
jspm: {
meta: {
'jspm_packages/github/angular/angular.js': {
format: 'global',
exports: 'angular'
},
'jspm_packages/github/angular/angular-mocks.js': {
format: 'global',
deps: 'angular'
}
},
loadFiles: [
'test/**/*.js'
],
serveFiles: [
'app/**/*.js'
]
},
My initial focus is to test a custom angular service :
// imports
class Game {
constructor($rootScope, $http, $timeout, $translate, $location) {
// ...
this.$rootScope.game = this;
}
}
Here is the content of my test file :
import { module, inject } from 'angular-mocks';
describe('this is a test', function () {
beforeEach(module('module-name'));
var game;
beforeEach(inject(function(_game_) {
game = new _game_;
}));
it('should be defined', function () {
expect(game).toBeDefined();
});
});
The issue I am facing is that I keep encountering an error. The inject
function from angular-mocks appears to be malfunctioning as my variable game
remains undefined when it shouldn't be.
PhantomJS 2.1.1 (Windows 8 0.0.0) should be defined FAILED
forEach
loadModules
createInjector
workFn
{path}/node_modules/karma-jspm/src/adapter.js:61:24
tryCatchReject@D:/{path}/jspm_packages/system-polyfills.src.js:1188:34
runContinuation1@D:/{path}/jspm_packages/system-polyfills.src.js:1147:18
when@D:/{path}/jspm_packages/system-polyfills.src.js:935:20
run@D:/{path}/jspm_packages/system-polyfills.src.js:826:17
_drain@D:/{path}/jspm_packages/system-polyfills.src.js:102:22
drain@D:/{path}/jspm_packages/system-polyfills.src.js:67:15
Expected undefined to be defined.
D:/{path}/node_modules/karma-jspm/src/adapter.js:61:24
tryCatchReject@D:/{path}/jspm_packages/system-polyfills.src.js:1188:34
runContinuation1@D:/{path}/jspm_packages/system-polyfills.src.js:1147:18
when@D:/{path}/jspm_packages/system-polyfills.src.js:935:20
run@D:/{path}/jspm_packages/system-polyfills.src.js:826:17
_drain@D:/{path}/jspm_packages/system-polyfills.src.js:102:22
drain@D:/{path}/jspm_packages/system-polyfills.src.js:67:15
I'm at a loss trying to figure out why it's not functioning properly. Any suggestions would be greatly appreciated.