"在每个"之前hook:workFn错误

时间:2016-06-07 07:25:03

标签: angularjs mocha karma-runner

我正在使用业力和幻影运行我的测试,我也使用mocha和sinon并且测试失败并出现以下错误:

create table 
#test
(
id int,
langspoken varchar(100)
)


insert into #test
select 1,'en,fr,ger,en_us'
union all
select  2,'en,fr'


select * from #test t
cross apply
dbo.SplitStrings_Numbers(t.langspoken,',') 
where item='en'

示例代码:

EditResourceCategoryDialogTest EditResourceCategoryDialogController "before each" hook: workFn
Error: [$injector:modulerr] http://errors.angularjs.org/1.4.9/$injector/modulerr?p0=resourceofferingsApp&p1=Error%3A%20%5B%24injector%3Amodulerr%5D%20

这里完全失败了:

define(function (require) {
    "use strict";

    var assert = require('chai').assert;
    var sinon = require('sinon');
    var angular = require('angular');
    var angularMocks = require('angular.mocks');

    require('resourceofferings/app');
    require('dialog path');

    describe('EditResourceCategoryDialogTest', function () {

        beforeEach(module('resourceofferingsApp'));

        describe('EditResourceCategoryDialogController', function () {
            var $scope, ctrl;

            //you need to inject dependencies first
            beforeEach(inject(function ($rootScope, $injector) {
                $scope = $rootScope.$new();
            }));

            it('initialization test (create mode)', inject(function ($controller) {

                ctrl = $controller("EditResourceCategoryDialogController", {
                    $scope: $scope,
                    $uibModalInstance: null,
                    options: {
                        isEditMode: false
                    }
                });

                assert.equal($scope.isEditMode, false);
            }));

        });
    });
});

请帮我解决这个问题..

提前致谢。

1 个答案:

答案 0 :(得分:0)

试试这个......

describe('controllers', function(){
    beforeEach(inject(function($rootScope, $controller) {
        scope = $rootScope.$new(); // this is what you missed out
        controller = $controller('EditResourceCategoryDialogController', {
            $scope: scope,
            $uibModalInstance: null,
            options: {
                isEditMode: false
            }
        });
    }));
});

更新:根据Angular ......

  

模块无法加载的一个常见原因是您已经忘记了   包含具有已定义模块的文件或文件不能包含的文件   加载。

您确定所有需要的文件都已加载吗?