在本地运行我的单元测试工作正常,但在构建服务器上发生了最愚蠢的事情:有时他们通过,有时他们没有.主要代码:
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"); }); ...
在构建服务器日志中,我有时可以阅读:
TypeError: undefined is not an object (evaluating
‘scope.myImportantAssignment = variableName’)
在控制台上我可以读到:
>日志:’进入 – 初始化模块……’
>日志:’退出 – 初始化模块……’
>日志:’进入 – 测试A’
这可能表明第二个beforeEach根本没有被调用,因此范围没有被初始化.但为什么?在我看来,处理应该像:
>在每个1之前
>在每个2之前
>它
但事实似乎并非如此.是不是有异步问题?非常感谢任何一点提示,因为如果它们有时会失败,我根本无法使用这些测试……