Skip to content

Commit

Permalink
Ensure an error message is returned when giving wrong arguments to `.…
Browse files Browse the repository at this point in the history
…keys`
  • Loading branch information
astorije committed Nov 27, 2017
1 parent b41dfb3 commit b75f788
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion chai-immutable.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
case 'Array':
if (arguments.length > 1) {
throw new chai.AssertionError(
'when testing keys against an object or an array you must ' +
'when testing keys against an immutable collection, you must ' +
'give a single Array|Object|String|Collection argument or ' +
'multiple String arguments',
null,
Expand Down
13 changes: 13 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,19 @@ describe('chai-immutable', function () { // eslint-disable-line prefer-arrow-cal
expect(map).to.have.deep.keys(new Map({ x: 6, y: 7 }));
});

it('should error when given multiple non-scalar arguments', function () { // eslint-disable-line prefer-arrow-callback
const msg = 'when testing keys against an immutable collection, ' +
'you must give a single Array|Object|String|Collection argument or ' +
'multiple String arguments';

fail(() => expect(map).to.have.all.keys(['x'], 'y'), msg);
fail(() => expect(map).to.have.deep.keys(new List(['x']), 'y'), msg);
fail(() => expect(map).to.have.deep.keys(new Set(['x']), 'y'), msg);
fail(() => expect(map).to.have.deep.keys(new Stack(['x']), 'y'), msg);
fail(() => expect(map).to.have.all.keys({ x: 1 }, 'y'), msg);
fail(() => expect(map).to.have.all.keys(new Map({ x: 1 }), 'y'), msg);
});

it('should pass using `any` given an existing key', function () { // eslint-disable-line prefer-arrow-callback
expect(map).to.have.any.keys('x', 'z');
expect(map).to.have.any.deep.keys('x', 'z');
Expand Down

0 comments on commit b75f788

Please sign in to comment.