已经在业力,摩卡柴和sinon试过一个测试用例。角度测试类型错误
一旦我使用该服务,我会收到错误信息。这是我的错误。请任何帮助。
AssertionError: expected undefined to deeply equal 'strong'
at /var/www/html/Testing/mocha/node_modules/chai/chai.js:210
at assertEql (/var/www/html/Testing/mocha/node_modules/chai/chai.js:784)
at /var/www/html/Testing/mocha/node_modules/chai/chai.js:3854
at /var/www/html/Testing/mocha/www/index-controller.test.js:22
PhantomJS 1.9.8 (Linux 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.043 secs/0.002 secs)
这是我indexcontroller.js
'use strict';
angular.module('beatso.index-controller', [])
.controller('IndexController', function(
commanService) {
(function(vm){
angular.extend(vm, {
checkPassword: checkPassword
})
vm.headingTop = "Beatso A Music Fanatic Group";
vm.password = "verystrogpassword";
function checkPassword() {
return commanService.passwordValidator("vm.password");
}
})(this);
});
这是我的IndexController测试。 indeccontroller.test.js
这是我常用的服务
'use strict';
angular.module('beatso-comman.service', [])
.factory('commanService', function(){
var service = {
passwordValidator: passwordValidator
}
function passwordValidator(password){
if(password.length >= 8) {
return 'strong'
}else {
return 'weak'
}
}
return service;
})
这里是我的服务测试。
'use strict'
describe('Test for my comman service', function(){
var cService;
beforeEach(module('beatso-comman.service'));
beforeEach(inject(initCommanService));
it('It should check the password strength', function(){
expect(cService.passwordValidator('amtoverystrongpassword')).to.eql('strong');
});
function initCommanService(commanService){
cService = commanService;
}
})
顺便说一句,删除引号'passwordValidator( “vm.password”)',只要你想检查*值* vm.password'的'。 –
谢谢@ MichaelP.Bazos但是我的问题还没有解决。你能帮我么。 –
我知道这不是''undefined'不是函数'的原因。你的主要问题是你想用一个模拟服务来测试服务方法,它没有方法。 –