Angular Js:简单的单元测试不起作用
Angular Js: Simple unit test not working
情况:
我正在尝试为我的角度应用程序设置单元测试。我已经创建了一个基本的测试角度应用程序并编写了一个简单的单元测试,但没有按预期工作。
该应用程序:
var app = angular.module( 'myApp', [] );
app.controller('InitCtrl', function( $scope, Person )
{
$scope.test_person = Person.Person("Tom");
})
app.factory('Person', function(){
return {
Person: function(name){
this.name = name;
console.log ( name );
}
}
})
单元测试:
describe('Person', function () {
var Person;
beforeEach(module('myApp'));
beforeEach(inject(function (_Person_) {
Person = _Person_;
}));
describe('Constructor', function () {
it('assigns a name', function () {
expect(new Person('Ben')).to.have.property('name', 'Ben');
});
});
});
错误消息:
当我运行测试时,我收到实际的错误消息:
PhantomJS 1.9.8 (Mac OS X 0.0.0) Person "before each" hook: workFn for "assigns a name" FAILED
Error: [$injector:modulerr] Failed to instantiate module myApp due to:
Error: [$injector:nomod] Module 'myApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.4.4/$injector/nomod?p0=myApp
尝试:
我尝试过使用不同的 sintax:
var app = angular.module( 'myApp' );
但这并不能解决问题。
问题:
这个简单的测试出了什么问题?
应用程序中缺少某些内容,或者测试中存在错误?
谢谢!
很可能
你没有加载你的应用程序.js在你的业力配置文件中:
module.exports = function(config) {
config.set({
basePath: '',
files: [
'../../path/to/app.js',
//...
相关文章:
- getRange(单元格)在谷歌应用程序脚本中不起作用
- Object.defineProperty()在测试(jpm运行)过程中有效,但不起作用;使用实际xpi时,不要执行任何
- 摩卡/柴异步测试 'done()' fn 不起作用
- JavaScript 我测试密码的函数不起作用
- 谷歌地理图表点击设置单元格不起作用
- GWO 测试:多个测试页面在预览中不起作用
- 简单的要求JS测试不起作用
- jQueryAjax测试不起作用
- 选择:使用jquery的可见表单元格不起作用
- JavaScriptgetter的Jasmine测试不起作用
- Angular Js:简单的单元测试不起作用
- Karma + AngularJS +剑道:剑道网格测试不起作用
- 贾斯敏间谍测试不起作用
- expect - response在AngularJS单元测试(Jasmine)中不起作用
- Jquery中的简单测试不起作用.绿色方块没有显示出来
- Angular指令的Jasmine测试不起作用
- Javascript Internet连接测试不起作用
- 英国假期测试不起作用
- 我无法弄清楚为什么这个 cookie 测试不起作用
- AJAX 测试不起作用