I got the following error
PhantomJS 2.1.1 (Linux 0.0.0) leave API service create(): should create a leave FAILED
static/app.min.js:4804:54
forEach@static/app.min.js:440:25
loadModules@static/app.min.js:4764:13
createInjector@static/app.min.js:4686:31
WorkFn@node_modules/angular-mocks/angular-mocks.js:3120:60
loaded@http://localhost:9876/context.js:151:17
TypeError: undefined is not an object (evaluating '$httpBackend.expectPOST') in test/leave.service.tests.js (line 65)
test/leave.service.tests.js:65:16
loaded@http://localhost:9876/context.js:151:17
Test
var chai = require('chai');
var assert = chai.assert;
require('../src2/pages/leaves/leave.service.js');
describe('leave API service', function () {
var service;
var $httpBackend;
beforeEach(angular.mock.module('app'));
beforeEach(inject(function (_$httpBackend_, LeaveService) {
$httpBackend = _$httpBackend_;
service = LeaveService;
}));
it('create(): should create a leave', function (done) {
var leave = {name: 'test'};
$httpBackend.expectPOST('/api/leave/', leave).respond(201, leave);
service.create(leave).then(function () {
done();
});
$httpBackend.flush();
});
});
webpack-related config in Karma.conf.js
files: [
'./static/app.min.js',
'node_modules/angular-mocks/angular-mocks.js',
{pattern: 'test/leave.service.tests.js', watched: false}
],
preprocessors: {
'test/leave.service.tests.js': ['webpack']
},
Do you know why I got trouble with the injection?
来源:https://stackoverflow.com/questions/41618626/karma-webpackangular-typeerror-undefined-is-not-an-object-evaluating-httpba