Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tests pass with --use_strict #1040

Merged
merged 3 commits into from Sep 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/chai/core/assertions.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
Expand Down
9 changes: 1 addition & 8 deletions test/assert.js
Expand Up @@ -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(){
Expand Down
10 changes: 1 addition & 9 deletions test/expect.js
Expand Up @@ -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(){
Expand Down
10 changes: 1 addition & 9 deletions test/should.js
Expand Up @@ -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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the message is a bit misleading: TypeError is thrown because rhs.prototype is primitive, type of rhs is OK.


if (typeof Symbol !== 'undefined' && typeof Symbol.hasInstance !== 'undefined') {
err(function(){
Expand Down
18 changes: 10 additions & 8 deletions test/utilities.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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!'
}
}
);

Expand Down Expand Up @@ -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!'
}
}
);

Expand Down