首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >茉莉花试验基因敲除ObservableArray

茉莉花试验基因敲除ObservableArray
EN

Stack Overflow用户
提问于 2015-01-19 15:06:50
回答 2查看 1.1K关注 0票数 0

更新

我已经更新了我的测试和错误信息回来是非常混乱的..。

代码语言:javascript
复制
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 } ].

原始邮政

我对进行茉莉花测试非常陌生,所以这可能是一个简单的问题,但我真的找不到与我的情况相匹配的东西。

我使用下划线在数组中创建一个由五个对象组成的列表,每个对象中有两个Knockout observableArray()。

代码语言:javascript
复制
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);

我不太清楚如何编写一个单元测试来检查数据库数组的初始状态。

代码语言:javascript
复制
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: []
            }
        ]);
    });
});
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-01-19 17:50:32

我想问题在于比较ko.observableArray()[]的相等性。

代码语言:javascript
复制
expect(vm.databases.length).toEqual(5);
expect(vm.databases[0].name).toEqual('DB 1');
expect(vm.databases[0].chosenRoles.length).toEqual(0);
expect(vm.databases[0].chosenModules.length).toEqual(0);
...
expect(vm.databases[4].name).toEqual('DB 5');
expect(vm.databases[4].chosenRoles.length).toEqual(0);
expect(vm.databases[4].chosenModules.length).toEqual(0);
票数 2
EN

Stack Overflow用户

发布于 2015-01-19 18:19:17

断言中的对象将chosenRoleschosenModules作为javascript数组。但你把它们做成了observableArrays。这意味着它们是真正的功能。

我可能会像上面might建议的那样做,但请记住对断言进行函数调用(添加括号)(并将toEqual更改为toBe,以便获得严格的相等)。

expect(vm.databases[0].chosenRoles().length).toBe(0); expect(vm.databases[0].chosenModules().length).toBe(0);

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28027643

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档