beforeEach在angularjs/requirejs场景中没有通过Karma/Jasmine调用

tim*_*tos 6 requirejs angularjs angularjs-scope karma-runner karma-jasmine

在本地运行我的单元测试工作正常,但在构建服务器上发生了最愚蠢的事情:有时他们通过,有时他们没有.主要代码:

define(['angmock', 'someMore'], function () {
    describe('myController', function () {
        beforeEach(function () {
        console.log("Entry - Initializing modules...");
        module('module1');
        module('module2');
        console.log("Exit - Initializing modules...");
    });

    var scope, controller;
    beforeEach(inject(function ($rootScope, $controller) {
        console.log("Entry - Creating scope...");

        scope = $rootScope.$new();
        controller = $controller('myController', {
            $scope: scope
        });

        console.log("Exit - Creating scope...");
    }));

    it('should test something', function () {
        console.log("Entry - Test A");
        scope.myImportantAssignment = variableName;
        ...
        console.log("Exit - Test A");
    });
...
Run Code Online (Sandbox Code Playgroud)

在构建服务器日志中,我有时可以阅读:

TypeError:undefined不是对象(评估'scope.myImportantAssignment = variableName')

在控制台上我可以读到:

  • 日志:'进入 - 初始化模块......'
  • 日志:'退出 - 初始化模块......'
  • 日志:'进入 - 测试A'

这可能表明第二个beforeEach根本没有被调用,因此范围没有被初始化.但为什么?在我看来,处理应该像:

  • 在每个1之前
  • 在每个2之前

但事实似乎并非如此.是不是有异步问题?非常感谢任何一点提示,因为如果它们有时会失败,我根本无法使用这些测试......

Est*_*ask 13

没有可以解释问题的竞争条件,块是同步的并且总是按顺序运行.如果应用程序无提示无法自举并引发,则可能会发生这种情况inject.

控制台中应该有错误,但PhantomJS以吞咽错误而闻名,将Karma启动器更改为Chrome可能会改善错误输出.

移动injectbeforeEachit还可以帮助查找问题,它使规范失败不是失败的预期,但是,这使得这种预期失败的错误.

在单元测试中,应用程序单元进行测试,其他所有内容都应该被模拟,具有额外的依赖关系(用于Kendo UI的Angular包装器)为规范添加了更多移动部件.