使用Webpack进行Angular Karma测试失败注入

时间:2016-06-07 16:36:26

标签: angularjs webpack karma-jasmine

我是一个用Typescript编写的相当大的Angular项目,我和Webpack合作过。这会生成一个在浏览器中加载的包,一切都很好。

现在我试图运行我迄今为止的几个Karma测试,这些测试在转换为磁盘上的Javascript时曾经工作过。试用2天后让事情变得更容易,我现在正在进行一次测试。会发生什么是Webpack步骤运行,Karma尝试在PhantomJS中运行测试。它给出了以下错误:

lua_pushstring

这意味着注入步骤尚未设置TypeError: undefined is not an object (evaluating 'browser.url') in /vagrant/itracker/media/website/js/test/admin/controllers/colsumObjectController.spec.ts (line 73)变量。实际上,我已经为该函数添加了一个控制台日志,它永远不会执行。

browser

输出:

    describe("ColsumObjectController", () => {
        const allColsumObjectsForProcess = { "count": 4, "next": null, "previous": null, "results": []};
        const allColsumOptions = { "count": 6, "next": null, "previous": null, "results": []};
        const allColsumFieldsForProcess = { "count": 6, "next": null, "previous": null, "results": []};

        beforeEach(angular.mock.module('adminApp'));

        var controller, browser, httpBackend, $scope, colsumObjectController;

        console.log('1. *****************************');
        beforeEach(angular.mock.inject( (_$controller_, _$browser_, _$httpBackend_) => {
            console.log(_$browser_);
            console.log('2. *****************************');
            controller = _$controller_;
            browser = _$browser_;
            httpBackend = _$httpBackend_;
        }));

        beforeEach(() => {

            console.log('3. *****************************');
            $scope = {};
            browser.url('http://127.0.0.1/process/admin/colsum-object-list-view/2/');

            httpBackend.whenGET('/rest/v1/colsum-objects/?process=2').respond(200, allColsumObjectsForProcess);
            httpBackend.whenGET('/rest/v1/colsum-options/').respond(200, allColsumOptions);
            httpBackend.whenGET('/rest/v1/colsum-fields/?process=2&page_size=9999').respond(200, allColsumFieldsForProcess);

            colsumObjectController = controller('ColsumObjectController', {$scope: $scope});

            httpBackend.flush();
        });
 // Rest of test

所以你可以看到第2步没有被执行。这是为什么?

0 个答案:

没有答案