Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.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
Javascript angularjs ui路线的mocha chai测试用例_Javascript_Angularjs_Mocha.js_Chai - Fatal编程技术网

Javascript angularjs ui路线的mocha chai测试用例

Javascript angularjs ui路线的mocha chai测试用例,javascript,angularjs,mocha.js,chai,Javascript,Angularjs,Mocha.js,Chai,我需要通过mocha chai介绍angularJs配置文件 我试过了 it('should load the page.', inject(function ($location, $rootScope, $state, $httpBackend) { $httpBackend.whenGET('scripts/select-line-module/views/select-line.html').respond('<div/>'); var state = $s

我需要通过mocha chai介绍angularJs配置文件

我试过了

it('should load the page.', inject(function ($location, $rootScope, $state, $httpBackend) {
    $httpBackend.whenGET('scripts/select-line-module/views/select-line.html').respond('<div/>');
    var state = $state.get('selectLine');
    $rootScope.$digest();
    assert.isDefined(state.templateUrl()); 
    expect(state.templateUrl).toBe('scripts/select-line-module/views/select-line.html');
}));
it('should load the page')、inject(函数($location、$rootScope、$state、$httpBackend){
$httpBackend.whenGET('scripts/select-line-module/views/select-line.html')。响应('';
var state=$state.get('selectLine');
$rootScope.$digest();
assert.isDefined(state.templateUrl());
expect(state.templateUrl).toBe('scripts/selectline模块/views/selectline.html');
}));
我能够介绍templateUrl函数,但测试用例失败 错误:未定义不是函数


我觉得我很亲近,但我在这里错过了什么?

你的看法和期望都改变了。您必须断言templateUrl函数已定义,并期望函数返回为字符串

assert.isDefined(state.templateUrl); expect(state.templateUrl()).toBe('scripts/select-line-module/views/select-line.html')

但是,您能否检查状态是否已定义?我认为它可以是未定义的。

我喜欢这样做

it('should load the page.', inject(function ($state) {
    var state = $state.get('selectLine');
    assert.isDefined(state.templateUrl()); 
    expect(state.templateUrl()).to.equal('scripts/select-line-module/views/select-line.html');
}));
这对我有用