Angularjs 在业力中获得角常数
鉴于应用程序启动:Angularjs 在业力中获得角常数,angularjs,ionic-framework,karma-runner,karma-jasmine,Angularjs,Ionic Framework,Karma Runner,Karma Jasmine,鉴于应用程序启动: angular.module("starter", [ "ionic" ]) .constant("DEBUG", true) .run(function() { /* ... */ }); 如何测试DEBUG的值 在尝试以下操作时: describe("app", function() { beforeEach(function() { module("starter"); }); des
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
确保在正确的位置实例化它。 在这种情况下,没有运行每个之前的
来加载模块,因为调试
正在描述
块中注入()
,而不是它
块中。以下各项工作正常:
describe("app", function() {
var DEBUG;
beforeEach(function() {
module("starter");
});
describe("constants", function() {
describe("DEBUG", function() {
it("should be a boolean", inject(function(DEBUG) {
expect(typeof DEBUG).toBe("boolean");
}));
});
});
});
将现有常数注入业力测试的简单方法
// Assuming your constant already exists
angular.module('app').constant('STACK', 'overflow')...
// Your Karma Test Suite
describe('app', function() {
var STACK;
beforeEach(module('APP'));
beforeEach(inject(function ($injector) {
STACK = $injector.get('STACK');
}));
// Tests...
});
显示“app_test.js”的第14、15、16行。…app_test.js
是第二个代码块。第14-16行是最后三行。