鉴于应用启动:
angular.module("starter",[ "ionic" ]) .constant("DEBUG",true) .run(function() { /* ... */ });
我该如何测试DEBUG的值?
尝试时:
describe("app",function() { beforeEach(function() { module("starter"); }); describe("constants",function() { describe("DEBUG",inject(function(DEBUG) { it("should be a boolean",function() { expect(typeof DEBUG).toBe("boolean"); }); })); }); });
我得到了
TypeError: 'null' is not an object (evaluating 'currentSpec.$modules') at workFn (/%%%/www/lib/angular-mocks/angular-mocks.js:2230) at /%%%/www/js/app_test.js:14 at /%%%/www/js/app_test.js:15 at /%%%/www/js/app_test.js:16
解决方法
确保它在正确的位置实例化.
在这种情况下,没有运行beforeEach来加载模块,因为DEBUG正在describe块中注入(),而不是它块.以下工作正常:
在这种情况下,没有运行beforeEach来加载模块,因为DEBUG正在describe块中注入(),而不是它块.以下工作正常:
describe("app",function() { var DEBUG; beforeEach(function() { module("starter"); }); describe("constants",function() { it("should be a boolean",inject(function(DEBUG) { expect(typeof DEBUG).toBe("boolean"); })); }); }); });