开发者

How to compare the output of serializeArray using qunit

I am using qunit and jquery. Latest version of both.

In my code when I submit the form I have the event as e. I call

e.serializeArray() 

Here is my test.

equals(args.data, [ { "name": "user_name", "value": "john" } ], 'input data');

And this is the error message from开发者_如何学JAVA qunit.

expected: [ { "name": "user_name", "value": "david" } ] result: [ { "name": "user_name", "value": "david" } ]

As you can see to the naked eye the expected and result value is same but qunit is not liking it.

I guess I am missing something.


You may want to look at deepEqual

module('QUnit');
test('equal and deepEqual', function () {
    expect(4);
    var a1 = [{ "name": "user_name", "value": "david" }];
    var a2 = [{ "name": "user_name", "value": "david" }];
    var b1 = [{ "name": "user_name", "value": "henry" }];
    equal(a1, a2); //should fail
    equal(a1, b1); //should fail
    deepEqual(a1, a2); //should pass
    deepEqual(a1, b1); //should fail
});

Further digging yielded (from the qunit.js code):

// Backwards compatibility, deprecated
QUnit.equals = QUnit.equal;
QUnit.same = QUnit.deepEqual;

I assume old on the left, new on the right.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜