Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 在业力中获得角常数_Angularjs_Ionic Framework_Karma Runner_Karma Jasmine - Fatal编程技术网

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行是最后三行。