Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arrays passed to .keys() assertions are sorted (unexpectedly) by side-effect #359

Merged
merged 1 commit into from
Feb 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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