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 6, 2015
1 parent dfd73ff commit 68f3c02
Show file tree
Hide file tree
Showing 3 changed files with 19 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
9 changes: 9 additions & 0 deletions test/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,15 @@ describe('expect', function () {

});

it('keys(array) will not mutate array (#359)', function () {
var expected = [ 'b', 'a' ];
var original_order = [ 'b', 'a' ];
var obj = { "b": 1, "a": 1 };
expect(expected).deep.equal(original_order);
expect(obj).keys(original_order);
expect(expected).deep.equal(original_order);
});

it('chaining', function(){
var tea = { name: 'chai', extras: ['milk', 'sugar', 'smile'] };
expect(tea).to.have.property('extras').with.lengthOf(3);
Expand Down
9 changes: 9 additions & 0 deletions test/should.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,15 @@ describe('should', function() {
}, "expected { foo: 1, bar: 2 } to not have keys 'foo', or 'baz'");
});

it('keys(array) will not mutate array (#359)', function () {
var expected = [ 'b', 'a' ];
var original_order = [ 'b', 'a' ];
var obj = { "b": 1, "a": 1 };
expected.should.deep.equal(original_order);
obj.should.keys(original_order);
expected.should.deep.equal(original_order);
});

it('throw', function () {
// See GH-45: some poorly-constructed custom errors don't have useful names
// on either their constructor or their constructor prototype, but instead
Expand Down

0 comments on commit 68f3c02

Please sign in to comment.