2

次のエラーが発生しました

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']
    },

なぜ私が注射に苦労したか知っていますか?

4

0 に答える 0