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 13f4f24..42860a7 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 errorMsg = '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'), errorMsg); + fail(() => expect(map).to.have.deep.keys(new List(['x']), 'y'), errorMsg); + fail(() => expect(map).to.have.deep.keys(new Set(['x']), 'y'), errorMsg); + fail(() => expect(map).to.have.deep.keys(new Stack(['x']), 'y'), errorMsg); + fail(() => expect(map).to.have.all.keys({'x': 1}, 'y'), errorMsg); + fail(() => expect(map).to.have.all.keys(new Map({'x': 1}), 'y'), errorMsg); + }); + 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');