Skip to content

Commit

Permalink
Fix #359 keys() sorts input unexpectedly
Browse files Browse the repository at this point in the history
  • Loading branch information
gregglind committed Feb 4, 2015
1 parent dfd73ff commit c0f7b76
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/chai/core/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ module.exports = function (chai, _) {
ok
, 'expected #{this} to ' + str
, 'expected #{this} to not ' + str
, expected.sort()
, expected.slice(0).sort()
, actual.sort()
, true
);
Expand Down
10 changes: 10 additions & 0 deletions test/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,16 @@ describe('expect', function () {
expect({ foo: 1, bar: 2 }).to.not.have.all.keys(['baz', 'foo']);
expect({ foo: 1, bar: 2 }).to.not.contain.all.keys(['baz', 'foo']);

// issues/359
(function fix359(){
var expected = ['b','a'];
var backup = expected.slice(0);
var obj = {"b":1, "a":1};
expect(expected).deep.equal(backup);
expect(obj).keys(expected);
expect(expected).deep.equal(backup);
})()

err(function(){
expect({ foo: 1 }).to.have.keys();
}, "keys required");
Expand Down
11 changes: 11 additions & 0 deletions test/should.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,17 @@ describe('should', function() {
({ foo: 1, bar: 2 }).should.not.have.all.keys(['baz', 'foo']);
({ foo: 1, bar: 2 }).should.not.contain.all.keys(['baz', 'foo']);


// issues/359
(function fix359(){
var expected = ['b','a'];
var backup = expected.slice(0);
var obj = {"b":1, "a":1};
expected.should.deep.equal(backup);
obj.should.keys(expected);
expected.should.deep.equal(backup);
})()

err(function(){
({ foo: 1 }).should.have.keys();
}, "keys required");
Expand Down

0 comments on commit c0f7b76

Please sign in to comment.