diff --git a/chai-immutable.js b/chai-immutable.js index c8ec5f1..f857ac1 100644 --- a/chai-immutable.js +++ b/chai-immutable.js @@ -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, diff --git a/test/test.js b/test/test.js index 8e82b94..4a3a2ec 100644 --- a/test/test.js +++ b/test/test.js @@ -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');