From 6586e2dcbe1fe5ee9f443b05809739baac103918 Mon Sep 17 00:00:00 2001 From: Aleksey Shvayka Date: Wed, 6 Sep 2017 22:18:25 +0300 Subject: [PATCH 1/3] add missing `var`s --- lib/chai/core/assertions.js | 5 +++++ test/utilities.js | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/chai/core/assertions.js b/lib/chai/core/assertions.js index 1600b2c98..069c5241b 100644 --- a/lib/chai/core/assertions.js +++ b/lib/chai/core/assertions.js @@ -1142,6 +1142,7 @@ module.exports = function (chai, _) { , ssfi = flag(this, 'ssfi') , objType = _.type(obj).toLowerCase() , nType = _.type(n).toLowerCase() + , errorMessage , shouldThrow = true; if (doLength) { @@ -1238,6 +1239,7 @@ module.exports = function (chai, _) { , ssfi = flag(this, 'ssfi') , objType = _.type(obj).toLowerCase() , nType = _.type(n).toLowerCase() + , errorMessage , shouldThrow = true; if (doLength) { @@ -1333,6 +1335,7 @@ module.exports = function (chai, _) { , ssfi = flag(this, 'ssfi') , objType = _.type(obj).toLowerCase() , nType = _.type(n).toLowerCase() + , errorMessage , shouldThrow = true; if (doLength) { @@ -1428,6 +1431,7 @@ module.exports = function (chai, _) { , ssfi = flag(this, 'ssfi') , objType = _.type(obj).toLowerCase() , nType = _.type(n).toLowerCase() + , errorMessage , shouldThrow = true; if (doLength) { @@ -1524,6 +1528,7 @@ module.exports = function (chai, _) { , objType = _.type(obj).toLowerCase() , startType = _.type(start).toLowerCase() , finishType = _.type(finish).toLowerCase() + , errorMessage , shouldThrow = true , range = (startType === 'date' && finishType === 'date') ? start.toUTCString() + '..' + finish.toUTCString() diff --git a/test/utilities.js b/test/utilities.js index 58b43c48e..eab6422d8 100644 --- a/test/utilities.js +++ b/test/utilities.js @@ -132,8 +132,8 @@ describe('utilities', function () { }); it('addMethod returns new assertion with flags copied over', function () { - assertion1 = expect('foo'); - assertion2 = assertion1.to.returnNewAssertion(); + var assertion1 = expect('foo'); + var assertion2 = assertion1.to.returnNewAssertion(); // Checking if a new assertion was returned expect(assertion1).to.not.be.equal(assertion2); @@ -413,8 +413,8 @@ describe('utilities', function () { }); it('addProperty returns a new assertion with flags copied over', function () { - assertion1 = expect('foo'); - assertion2 = assertion1.is.thing; + var assertion1 = expect('foo'); + var assertion2 = assertion1.is.thing; // Checking if a new assertion was returned expect(assertion1).to.not.be.equal(assertion2); From d4fde80a3cda3d9f1dd2c0a585a661d414b313f6 Mon Sep 17 00:00:00 2001 From: Aleksey Shvayka Date: Wed, 6 Sep 2017 22:19:10 +0300 Subject: [PATCH 2/3] fix instanceof rethrow test --- test/assert.js | 9 +-------- test/expect.js | 10 +--------- test/should.js | 10 +--------- 3 files changed, 3 insertions(+), 26 deletions(-) diff --git a/test/assert.js b/test/assert.js index ab12e2921..e3483ee97 100644 --- a/test/assert.js +++ b/test/assert.js @@ -180,19 +180,12 @@ describe('assert', function () { assert.instanceOf(new Foo(), undefined); }, "The instanceof assertion needs a constructor but undefined was given."); - var expectedError; - try { - t instanceof Thing; - } catch (err) { - errMsg = '[object Object] instanceof function Thing(){} failed: ' + err.message + '.'; - } - err(function(){ function Thing(){}; var t = new Thing(); Thing.prototype = 1337; assert.instanceOf(t, Thing); - }, expectedError, true); + }, 'The instanceof assertion needs a constructor but function was given.', true); if (typeof Symbol !== 'undefined' && typeof Symbol.hasInstance !== 'undefined') { err(function(){ diff --git a/test/expect.js b/test/expect.js index 043c734e5..0b5a0e5b2 100644 --- a/test/expect.js +++ b/test/expect.js @@ -413,20 +413,12 @@ describe('expect', function () { expect(new Foo()).to.an.instanceof(undefined); }, "The instanceof assertion needs a constructor but undefined was given."); - // Different browsers may have different error messages - var expectedError; - try { - t instanceof Thing; - } catch (err) { - errMsg = '[object Object] instanceof function Thing(){} failed: ' + err.message + '.'; - } - err(function(){ function Thing(){}; var t = new Thing(); Thing.prototype = 1337; expect(t).to.an.instanceof(Thing); - }, expectedError, true) + }, 'The instanceof assertion needs a constructor but function was given.', true) if (typeof Symbol !== 'undefined' && typeof Symbol.hasInstance !== 'undefined') { err(function(){ diff --git a/test/should.js b/test/should.js index 4585bfc1b..1453512d6 100644 --- a/test/should.js +++ b/test/should.js @@ -455,20 +455,12 @@ describe('should', function() { new Foo().should.be.an.instanceof(undefined); }, "The instanceof assertion needs a constructor but undefined was given."); - // Different browsers may have different error messages - var expectedError; - try { - t instanceof Thing; - } catch (err) { - errMsg = '[object Object] instanceof function Thing(){} failed: ' + err.message + '.'; - } - err(function(){ function Thing(){}; var t = new Thing(); Thing.prototype = 1337; t.should.be.an.instanceof(Thing); - }, expectedError, true); + }, 'The instanceof assertion needs a constructor but function was given.', true); if (typeof Symbol !== 'undefined' && typeof Symbol.hasInstance !== 'undefined') { err(function(){ From 300b994ad3adc5cb09aaeabb7f01fe78c422ffe7 Mon Sep 17 00:00:00 2001 From: Aleksey Shvayka Date: Wed, 6 Sep 2017 22:19:26 +0300 Subject: [PATCH 3/3] do not attempt to define properties on primitives --- test/utilities.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/utilities.js b/test/utilities.js index eab6422d8..50963f2f1 100644 --- a/test/utilities.js +++ b/test/utilities.js @@ -829,8 +829,9 @@ describe('utilities', function () { new chai.Assertion(this._obj).to.be.equal('x'); } , function () { - this._obj = this._obj || {}; - this._obj.__x = 'X!' + if (this._obj === Object(this._obj)) { + this._obj.__x = 'X!' + } } ); @@ -939,8 +940,9 @@ describe('utilities', function () { new chai.Assertion(this._obj).to.be.equal('x'); } , function () { - this._obj = this._obj || {}; - this._obj.__x = 'X!' + if (this._obj === Object(this._obj)) { + this._obj.__x = 'X!' + } } );