Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/chai/interface/should.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ module.exports = function (chai, util) {
function loadShould () {
// explicitly define this method as function as to have it's name to include as `ssfi`
function shouldGetter() {
if (this instanceof String || this instanceof Number || this instanceof Boolean ) {
if (this instanceof String
|| this instanceof Number
|| this instanceof Boolean
|| typeof Symbol === 'function' && this instanceof Symbol) {
return new Assertion(this.valueOf(), null, shouldGetter);
}
return new Assertion(this, null, shouldGetter);
Expand Down
51 changes: 51 additions & 0 deletions test/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,22 @@ describe('assert', function () {
it('equal', function () {
var foo;
assert.equal(foo, undefined);

if (typeof Symbol === 'function') {
var sym = Symbol();
assert.equal(sym, sym);
}
});

it('typeof', function () {
assert.typeOf('test', 'string');
assert.typeOf(true, 'boolean');
assert.typeOf(5, 'number');

if (typeof Symbol === 'function') {
assert.typeOf(Symbol(), 'symbol');
}

err(function () {
assert.typeOf(5, 'string');
}, "expected 5 to be a string");
Expand Down Expand Up @@ -182,6 +191,12 @@ describe('assert', function () {
it('notEqual', function() {
assert.notEqual(3, 4);

if (typeof Symbol === 'function') {
var sym1 = Symbol()
, sym2 = Symbol();
assert.notEqual(sym1, sym2);
}

err(function () {
assert.notEqual(5, 5);
}, "expected 5 to not equal 5");
Expand All @@ -190,6 +205,11 @@ describe('assert', function () {
it('strictEqual', function() {
assert.strictEqual('foo', 'foo');

if (typeof Symbol === 'function') {
var sym = Symbol();
assert.strictEqual(sym, sym);
}

err(function () {
assert.strictEqual('5', 5);
}, "expected \'5\' to equal 5");
Expand All @@ -198,6 +218,12 @@ describe('assert', function () {
it('notStrictEqual', function() {
assert.notStrictEqual(5, '5');

if (typeof Symbol === 'function') {
var sym1 = Symbol()
, sym2 = Symbol();
assert.notStrictEqual(sym1, sym2);
}

err(function () {
assert.notStrictEqual(5, 5);
}, "expected 5 to not equal 5");
Expand Down Expand Up @@ -435,6 +461,12 @@ describe('assert', function () {
assert.include([ 1, 2, 3], 3);
assert.include({a:1, b:2}, {b:2});

if (typeof Symbol === 'function') {
var sym1 = Symbol()
, sym2 = Symbol();
assert.include([sym1, sym2], sym1);
}

err(function () {
assert.include('foobar', 'baz');
}, "expected \'foobar\' to include \'baz\'");
Expand All @@ -460,6 +492,13 @@ describe('assert', function () {
assert.notInclude('foobar', 'baz');
assert.notInclude([ 1, 2, 3 ], 4);

if (typeof Symbol === 'function') {
var sym1 = Symbol()
, sym2 = Symbol()
, sym3 = Symbol();
assert.notInclude([sym1, sym2], sym3);
}

err(function(){
assert.notInclude(true, true);
}, "object tested must be an array, an object, or a string, but boolean given");
Expand Down Expand Up @@ -1256,6 +1295,10 @@ describe('assert', function () {
assert[isNotExtensible]('foo');
assert[isNotExtensible](false);
assert[isNotExtensible](undefined);

if (typeof Symbol === 'function') {
assert[isNotExtensible](Symbol());
}
});
});

Expand All @@ -1276,6 +1319,10 @@ describe('assert', function () {
assert[isSealed]('foo');
assert[isSealed](false);
assert[isSealed](undefined);

if (typeof Symbol === 'function') {
assert[isSealed](Symbol());
}
});
});

Expand Down Expand Up @@ -1330,6 +1377,10 @@ describe('assert', function () {
assert[isFrozen]('foo');
assert[isFrozen](false);
assert[isFrozen](undefined);

if (typeof Symbol === 'function') {
assert[isFrozen](Symbol());
}
});
});

Expand Down
34 changes: 34 additions & 0 deletions test/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ describe('expect', function () {
expect(function() {}).to.be.a('function');
expect(null).to.be.a('null');

if (typeof Symbol === 'function') {
expect(Symbol()).to.be.a('symbol');
}

err(function(){
expect(5).to.not.be.a('number', 'blah');
}, "blah: expected 5 not to be a number");
Expand Down Expand Up @@ -300,6 +304,11 @@ describe('expect', function () {
expect(1).to.eql(1);
expect('4').to.not.eql(4);

if (typeof Symbol === 'function') {
var sym = Symbol();
expect(sym).to.eql(sym);
}

err(function(){
expect(4).to.eql(3, 'blah');
}, 'blah: expected 4 to deeply equal 3');
Expand All @@ -319,6 +328,11 @@ describe('expect', function () {
expect('test').to.equal('test');
expect(1).to.equal(1);

if (typeof Symbol === 'function') {
var sym = Symbol();
expect(sym).to.equal(sym);
}

err(function(){
expect(4).to.equal(3, 'blah');
}, 'blah: expected 4 to equal 3');
Expand Down Expand Up @@ -624,6 +638,14 @@ describe('expect', function () {
expect([{a:1}]).to.include({a:1});
expect([{a:1}]).to.not.include({b:1});

if (typeof Symbol === 'function') {
var sym1 = Symbol()
, sym2 = Symbol()
, sym3 = Symbol();
expect([sym1, sym2]).to.include(sym1);
expect([sym1, sym2]).to.not.include(sym3);
}

err(function(){
expect(['foo']).to.include('bar', 'blah');
}, "blah: expected [ 'foo' ] to include 'bar'");
Expand Down Expand Up @@ -1283,6 +1305,10 @@ describe('expect', function () {
expect(false).to.not.be.extensible;
expect(undefined).to.not.be.extensible;

if (typeof Symbol === 'function') {
expect(Symbol()).to.not.be.extensible;
}

err(function() {
expect(42).to.be.extensible;
}, 'expected 42 to be extensible');
Expand Down Expand Up @@ -1326,6 +1352,10 @@ describe('expect', function () {
expect(false).to.be.sealed;
expect(undefined).to.be.sealed;

if (typeof Symbol === 'function') {
expect(Symbol()).to.be.sealed;
}

err(function() {
expect(42).to.not.be.sealed;
}, 'expected 42 to not be sealed');
Expand Down Expand Up @@ -1369,6 +1399,10 @@ describe('expect', function () {
expect(false).to.be.frozen;
expect(undefined).to.be.frozen;

if (typeof Symbol === 'function') {
expect(Symbol()).to.be.frozen;
}

err(function() {
expect(42).to.not.be.frozen;
}, 'expected 42 to not be frozen');
Expand Down
34 changes: 34 additions & 0 deletions test/should.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ describe('should', function() {
([]).should.be.a('array');
(function() {}).should.be.a('function');

if (typeof Symbol === 'function') {
Symbol().should.be.a('symbol');
}

(5).should.be.a('number');

err(function(){
Expand Down Expand Up @@ -301,6 +305,11 @@ describe('should', function() {
(1).should.eql(1);
'4'.should.not.eql(4);

if (typeof Symbol === 'function') {
var sym = Symbol();
sym.should.eql(sym);
}

err(function(){
(4).should.eql(3, 'blah');
}, 'blah: expected 4 to deeply equal 3');
Expand All @@ -310,6 +319,11 @@ describe('should', function() {
'test'.should.equal('test');
(1).should.equal(1);

if (typeof Symbol === 'function') {
var sym = Symbol();
sym.should.equal(sym);
}

err(function(){
(4).should.equal(3, 'blah');
}, 'blah: expected 4 to equal 3');
Expand Down Expand Up @@ -484,6 +498,14 @@ describe('should', function() {
({a:1,b:2}).should.include({b:2});
({a:1,b:2}).should.not.include({b:3});

if (typeof Symbol === 'function') {
var sym1 = Symbol()
, sym2 = Symbol()
, sym3 = Symbol();
[sym1, sym2].should.include(sym1);
[sym1, sym2].should.not.include(sym3);
}

err(function(){
['foo'].should.include('bar', 'blah');
}, "blah: expected [ 'foo' ] to include 'bar'");
Expand Down Expand Up @@ -1132,6 +1154,10 @@ describe('should', function() {
'foo'.should.not.be.extensible;
false.should.not.be.extensible;

if (typeof Symbol === 'function') {
Symbol().should.not.be.extensible;
}

err(function() {
(42).should.be.extensible;
}, 'expected 42 to be extensible');
Expand Down Expand Up @@ -1165,6 +1191,10 @@ describe('should', function() {
'foo'.should.be.sealed;
false.should.be.sealed;

if (typeof Symbol === 'function') {
Symbol().should.be.sealed;
}

err(function() {
(42).should.not.be.sealed;
}, 'expected 42 to not be sealed');
Expand Down Expand Up @@ -1198,6 +1228,10 @@ describe('should', function() {
'foo'.should.be.frozen;
false.should.be.frozen;

if (typeof Symbol === 'function') {
Symbol().should.be.frozen;
}

err(function() {
(42).should.not.be.frozen;
}, 'expected 42 to not be frozen');
Expand Down