错误:意外的请求:GET预期没有更多的请求[Karma and angularjs 1.7]

时间:2019-02-28 11:22:48

标签: angularjs unit-testing karma-jasmine

业力会议

    // list of files / patterns to load in the browser
    files: [
      '../Scripts/angular.js',
      '../Scripts/angular-mocks.js',
      '../Scripts/angular-route.js',
      '../service.js',
      '../home-view/home-view.module.js',
      '../home-view/home-view.component.js',
      '../home-view/home-view.template.html',
      '../home-view/home-view.component.spec.js'
    ],


    // list of files / patterns to exclude
    exclude: [
    ],


    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
      '../home-view/home-view.template.html' : 'ng-html2js',
      '../home-view/home-view.component.spec.js' : ['coverage']
    },

    ngHtml2JsPreprocessor: {
      moduleName: 'templates'
    },

home-view.component.spec.js

'use strict';

describe('component test : home', function () {

    // add module reference you want to test
    beforeEach(module('homeView'));

    // add templates [from karma]
    beforeEach(module('templates'));

    var element;
    var scope;

    beforeEach(inject(function ($rootScope, $compile) {
        scope = $rootScope.$new();
        element = angular.element('<home-view></home-view>');
        scope.$apply(function () {
            $compile(element)(scope);
        });
    }));

    it('render the header text', function () {
        var title = element.find('a');
        expect(title.text()).toBe('Header Text');
    });
});

我收到此错误。

    Error: Unexpected request: GET home-view/home-view.template.html
    No more request expected
        at createFatalError (C:/Projects/IntervieweeApp/IntervieweeSPA/IntervieweeSPA/Scripts/angular-mocks.js:1569:19)
        at $httpBackend (C:/Projects/IntervieweeApp/IntervieweeSPA/IntervieweeSPA/Scripts/angular-mocks.js:1616:11)
        at sendReq (C:/Projects/IntervieweeApp/IntervieweeSPA/IntervieweeSPA/Scripts/angular.js:13257:9)
        at serverRequest (C:/Projects/IntervieweeApp/IntervieweeSPA/IntervieweeSPA/Scripts/angular.js:12998:16)
        at processQueue (C:/Projects/IntervieweeApp/IntervieweeSPA/IntervieweeSPA/Scripts/angular.js:17914:37)
        at C:/Projects/IntervieweeApp/IntervieweeSPA/IntervieweeSPA/Scripts/angular.js:17962:27
        at Scope.$digest (C:/Projects/IntervieweeApp/IntervieweeSPA/IntervieweeSPA/Scripts/angular.js:19075:15)
        at ChildScope.$apply (C:/Projects/IntervieweeApp/IntervieweeSPA/IntervieweeSPA/Scripts/angular.js:19463:24)
        at UserContext.<anonymous> (C:/Projects/IntervieweeApp/IntervieweeSPA/IntervieweeSPA/home-view/home-view.component.spec.js:17:15)
        at Object.invoke (C:/Projects/IntervieweeApp/IntervieweeSPA/IntervieweeSPA/Scripts/angular.js:5122:19)
        at <Jasmine>
        at window.inject.angular.mock.inject (C:/Projects/IntervieweeApp/IntervieweeSPA/IntervieweeSPA/Scripts/angular-mocks.js:3422:25)
        at Suite.<anonymous> (C:/Projects/IntervieweeApp/IntervieweeSPA/IntervieweeSPA/home-view/home-view.component.spec.js:14:16)
        at <Jasmine>
        at C:/Projects/IntervieweeApp/IntervieweeSPA/IntervieweeSPA/home-view/home-view.component.spec.js:3:1
    Error: Expected '' to be 'Header Text'.
        at <Jasmine>
        at UserContext.<anonymous> (C:/Projects/IntervieweeApp/IntervieweeSPA/IntervieweeSPA/home-view/home-view.component.spec.js:24:30)
        at <Jasmine>

为什么会出现此错误?我正在尝试为此组件编写单元测试,但尚未找到任何解决方案。即使我注释了控制器和模板中的所有代码,该错误也不会改变。我的测试写得正确吗?控制器中有http请求,但是即使没有请求,也不会发生任何变化。可能与控制器的参数有关吗?

0 个答案:

没有答案
相关问题