我收到以下错误
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
测试
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();
});
});
Karma.conf.js 中与 webpack 相关的配置
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']
},
你知道为什么我在注射时遇到麻烦吗?