Skip to content

Commit

Permalink
Merge pull request chaijs#359 from gregglind/b359-unexpected-keys-sort
Browse files Browse the repository at this point in the history
Arrays passed to `.keys()` assertions are sorted (unexpectedly) by side-effect
  • Loading branch information
keithamus committed Feb 6, 2015
2 parents dfd73ff + 68f3c02 commit bd72280
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
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
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
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 bd72280

Please sign in to comment.