From 1f8c65135d6d4506701180ff8f1ce215e285c4d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Sat, 12 Sep 2015 13:04:56 +0000 Subject: [PATCH] Remove multi-type support for a/an assertion --- lib/chai/core/assertions.js | 30 +++++++++--------------------- test/expect.js | 22 ---------------------- test/should.js | 22 ---------------------- 3 files changed, 9 insertions(+), 65 deletions(-) diff --git a/lib/chai/core/assertions.js b/lib/chai/core/assertions.js index f24cc071c..88378f495 100644 --- a/lib/chai/core/assertions.js +++ b/lib/chai/core/assertions.js @@ -125,7 +125,7 @@ module.exports = function (chai, _) { }); /** - * ### .a(types) + * ### .a(type) * * The `a` and `an` assertions are aliases that can be * used either as language chains or to assert a value's @@ -146,35 +146,23 @@ module.exports = function (chai, _) { * // language chain * expect(foo).to.be.an.instanceof(Foo); * - * When an array of strings is passed as argument of the assertion, the - * value's type must be one of them. - * - * expect(myScalar).to.be.a(['string', 'number', 'boolean']); - * expect([]).to.not.be.a(['string', 'number', 'boolean']); - * * @name a * @alias an - * @param {String|Array} types + * @param {String} type * @param {String} message _optional_ * @api public */ - function an (types, msg) { + function an (type, msg) { if (msg) flag(this, 'message', msg); - if (_.type(types) === 'string') types = [types]; - types = types.map(function (t) { return t.toLowerCase(); }); - var obj = flag(this, 'object'); - - var str = types.map(function (t, index) { - var art = ~[ 'a', 'e', 'i', 'o', 'u' ].indexOf(t.charAt(0)) ? 'an' : 'a'; - var or = types.length > 1 && index === types.length - 1 ? 'or ' : ''; - return or + art + ' ' + t; - }).join(', '); + type = type.toLowerCase(); + var obj = flag(this, 'object') + , article = ~[ 'a', 'e', 'i', 'o', 'u' ].indexOf(type.charAt(0)) ? 'an ' : 'a '; this.assert( - types.some(function (expected) { return _.type(obj) === expected; }) - , 'expected #{this} to be ' + str - , 'expected #{this} not to be ' + str + type === _.type(obj) + , 'expected #{this} to be ' + article + type + , 'expected #{this} not to be ' + article + type ); } diff --git a/test/expect.js b/test/expect.js index 7b72aa081..b6d25f605 100644 --- a/test/expect.js +++ b/test/expect.js @@ -119,28 +119,6 @@ describe('expect', function () { err(function(){ expect(5).to.not.be.a('number', 'blah'); }, "blah: expected 5 not to be a number"); - - expect('foo').to.be.a(['string', 'number', 'boolean']); - expect(42).to.be.a(['string', 'number', 'boolean']); - expect(true).to.be.a(['string', 'number', 'boolean']); - - err(function(){ - expect([]).to.be.a(['string', 'number', 'boolean']); - }, 'expected [] to be a string, a number, or a boolean'); - - expect([]).to.not.be.a(['string', 'number', 'boolean']); - - err(function(){ - expect('foo').to.not.be.a(['string', 'number', 'boolean']); - }, 'expected \'foo\' not to be a string, a number, or a boolean'); - - err(function(){ - expect(42).to.not.be.a(['string', 'number', 'boolean']); - }, 'expected 42 not to be a string, a number, or a boolean'); - - err(function(){ - expect(true).to.not.be.a(['string', 'number', 'boolean']); - }, 'expected true not to be a string, a number, or a boolean'); }); it('instanceof', function(){ diff --git a/test/should.js b/test/should.js index e11f5075c..8ee6a3a29 100644 --- a/test/should.js +++ b/test/should.js @@ -151,28 +151,6 @@ describe('should', function() { err(function(){ (5).should.not.be.a('number'); }, "expected 5 not to be a number"); - - 'foo'.should.be.a(['string', 'number', 'boolean']); - (42).should.be.a(['string', 'number', 'boolean']); - (true).should.be.a(['string', 'number', 'boolean']); - - err(function(){ - [].should.be.a(['string', 'number', 'boolean']); - }, 'expected [] to be a string, a number, or a boolean'); - - [].should.not.be.a(['string', 'number', 'boolean']); - - err(function(){ - 'foo'.should.not.be.a(['string', 'number', 'boolean']); - }, 'expected \'foo\' not to be a string, a number, or a boolean'); - - err(function(){ - (42).should.not.be.a(['string', 'number', 'boolean']); - }, 'expected 42 not to be a string, a number, or a boolean'); - - err(function(){ - (true).should.not.be.a(['string', 'number', 'boolean']); - }, 'expected true not to be a string, a number, or a boolean'); }); it('instanceof', function(){