【发布时间】:2015-01-19 15:06:50
【问题描述】:
更新
我已经更新了我的测试并且返回的错误消息非常令人困惑......
it('Should get the available databases', function () {
expect(vm.databases).toEqual([
{
name: 'DB 1',
chosenRoles: function() { return []; },
chosenModules: function () { return []; }
},
{
name: 'DB 2',
chosenRoles: function () { return []; },
chosenModules: function () { return []; }
},
{
name: 'DB 3',
chosenRoles: function () { return []; },
chosenModules: function () { return []; }
},
{
name: 'DB 4',
chosenRoles: function () { return []; },
chosenModules: function () { return []; }
},
{
name: 'DB 5',
chosenRoles: function () { return []; },
chosenModules: function () { return []; }
}
]);
});
Summary (1 tests failed)
x User Management Initial state Should get the available databases
Expected [ { name : 'DB 1', chosenRoles : Function, chosenModules : Functi
}, { name : 'DB 2', chosenRoles : Function, chosenModules : Function }, { nam
: 'DB 3', chosenRoles : Function, chosenModules : Function }, { name : 'DB 4',
hosenRoles : Function, chosenModules : Function }, { name : 'DB 5', chosenRole
: Function, chosenModules : Function } ] to equal [ { name : 'DB 1', chosenRol
: Function, chosenModules : Function }, { name : 'DB 2', chosenRoles : Functi
, chosenModules : Function }, { name : 'DB 3', chosenRoles : Function, chosenM
ules : Function }, { name : 'DB 4', chosenRoles : Function, chosenModules : Fu
tion }, { name : 'DB 5', chosenRoles : Function, chosenModules : Function } ].
原帖
我对运行 Jasmine 测试非常陌生,所以这可能是一个简单的问题,但我真的找不到任何符合我情况的东西。
我正在使用下划线在一个数组中创建一个包含五个对象的列表,其中每个对象包含两个 Knockout observableArray()。
var pfp = pfp || {};
pfp.insight = pfp.insight || {};
pfp.insight.controllers = pfp.insight.controllers || {};
(function() {
'use strict';
this.settingsController = function() {
var root = this;
root.databases = _.range(5).map(function (i) {
return {
name: 'DB ' + (i + 1),
chosenRoles: ko.observableArray(),
chosenModules: ko.observableArray()
};
});
};
}).call(pfp.insight.controllers);
我不确定如何编写检查数据库数组初始状态的单元测试。
describe('User Management', function () {
'use strict';
var vm,
databases = [];
describe('Initial state', function() {
beforeEach(function () {
vm = new pfp.insight.controllers.settingsController();
});
it('Should get the available databases', function() {
expect(vm.databases).toEqual([
{
name: 'DB 1',
chosenRoles: [],
chosenModules: []
},
{
name: 'DB 2',
chosenRoles: [],
chosenModules: []
},
{
name: 'DB 3',
chosenRoles: [],
chosenModules: []
},
{
name: 'DB 4',
chosenRoles: [],
chosenModules: []
},
{
name: 'DB 5',
chosenRoles: [],
chosenModules: []
}
]);
});
});
【问题讨论】:
标签: javascript unit-testing knockout.js jasmine automated-tests