From b75f7883f7f1b123425ffdb0a1bfc3c11b61df71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Mon, 27 Nov 2017 01:29:26 -0500 Subject: [PATCH] Ensure an error message is returned when giving wrong arguments to `.keys` --- chai-immutable.js | 2 +- test/test.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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');