diff --git a/.karma-config/index.js b/.karma-config/index.js index 6e613cb1cd..ac0c878fa6 100644 --- a/.karma-config/index.js +++ b/.karma-config/index.js @@ -2,7 +2,7 @@ function getConfig() { var cfg = { frameworks: [ 'browserify', - 'should', + 'expect', 'mocha' ], files: [ diff --git a/CHANGELOG.md b/CHANGELOG.md index 199deaf47b..a644e93a9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +Unreleased +================== + +* [#2079], [#2231] - Add browser to CI + +[#2079]: https://github.com/mochajs/mocha/issues/2079 +[#2231]: https://github.com/mochajs/mocha/pull/2231 + 2.4.5 / 2016-01-28 ================== diff --git a/lib/utils.js b/lib/utils.js index 1ec27085fd..e5d214021c 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -12,6 +12,7 @@ var join = require('path').join; var readdirSync = require('fs').readdirSync; var statSync = require('fs').statSync; var watchFile = require('fs').watchFile; +var toISOString = require('to-iso-string'); /** * Ignored directories. @@ -479,9 +480,12 @@ function jsonStringify(object, spaces, depth) { : val.toString(); break; case 'date': - var sDate = isNaN(val.getTime()) // Invalid date - ? val.toString() - : val.toISOString(); + var sDate; + if (isNaN(val.getTime())) { // Invalid date + sDate = val.toString(); + } else { + sDate = val.toISOString ? val.toISOString() : toISOString(val); + } val = '[Date: ' + sDate + ']'; break; case 'buffer': diff --git a/package.json b/package.json index 63e191bd8f..52d1019e1b 100644 --- a/package.json +++ b/package.json @@ -250,7 +250,8 @@ "Jordan Sexton ", "Jussi Virtanen ", "Katie Gengler ", - "Kazuhito Hokamura " + "Kazuhito Hokamura ", + "Scott Santucci " ], "license": "MIT", "repository": { @@ -285,16 +286,18 @@ "browserify": "^13.0.0", "coffee-script": "~1.8.0", "eslint": "^1.2.1", + "expect.js": "^0.3.1", "karma": "^0.13.22", "karma-browserify": "^5.0.5", + "karma-expect": "^1.1.2", "karma-mocha": "^1.0.1", "karma-mocha-clean-reporter": "0.0.1", "karma-phantomjs-launcher": "^0.2.3", "karma-sauce-launcher": "^1.0.0", - "karma-should": "^1.0.0", "phantomjs": "1.9.8", "should": "~8.0.0", "through2": "~0.6.5", + "to-iso-string": "0.0.2", "watchify": "^3.7.0" }, "files": [ diff --git a/test/acceptance/context.js b/test/acceptance/context.js index 47c2db7083..69dea139c9 100644 --- a/test/acceptance/context.js +++ b/test/acceptance/context.js @@ -9,18 +9,18 @@ describe('Context', function(){ }) it('should work', function(){ - this.calls.should.eql(['before', 'before two']); + expect(this.calls).to.eql(['before', 'before two']); this.calls.push('test'); }) after(function(){ - this.calls.should.eql(['before', 'before two', 'test']); + expect(this.calls).to.eql(['before', 'before two', 'test']); this.calls.push('after two'); }) }) after(function(){ - this.calls.should.eql(['before', 'before two', 'test', 'after two']); + expect(this.calls).to.eql(['before', 'before two', 'test', 'after two']); }) }) @@ -36,7 +36,7 @@ describe('Context Siblings', function(){ }) it('should work', function(){ - this.hiddenFromSibling.should.eql('This should be hidden') + expect(this.hiddenFromSibling).to.eql('This should be hidden') }) }) @@ -46,27 +46,27 @@ describe('Context Siblings', function(){ }) it('should not have value set within a sibling describe', function(){ - 'This should be hidden'.should.not.eql(this.hiddenFromSibling); + expect('This should be hidden').not.to.eql(this.hiddenFromSibling); this.visibleFromTestSibling = 'Visible from test sibling'; }) it('should allow test siblings to modify shared context', function(){ - 'Visible from test sibling'.should.eql(this.visibleFromTestSibling); + expect('Visible from test sibling').to.eql(this.visibleFromTestSibling); }) it('should have reset this.calls before describe', function(){ - this.calls.should.eql(['before', 'before sibling']); + expect(this.calls).to.eql(['before', 'before sibling']); }) }) after(function(){ - this.calls.should.eql(['before', 'before sibling']); + expect(this.calls).to.eql(['before', 'before sibling']); }) }) describe('timeout()', function(){ it('should return the timeout', function(){ - this.timeout().should.equal(200); + expect(this.timeout()).to.equal(200); }); }); diff --git a/test/acceptance/http.js b/test/acceptance/http.js index 1dfa9146a4..43b8588508 100644 --- a/test/acceptance/http.js +++ b/test/acceptance/http.js @@ -9,7 +9,7 @@ server.listen(8888); describe('http', function(){ it('should provide an example', function(done){ http.get({ path: '/', port: 8888 }, function(res){ - res.should.have.property('statusCode', 200); + expect(res).to.have.property('statusCode', 200); done(); }) }) diff --git a/test/acceptance/interfaces/bdd.js b/test/acceptance/interfaces/bdd.js index bea1db2295..ba444c8f7f 100644 --- a/test/acceptance/interfaces/bdd.js +++ b/test/acceptance/interfaces/bdd.js @@ -1,34 +1,32 @@ -describe('Array', function(){ - describe('#indexOf()', function(){ - it('should return -1 when the value is not present', function(){ - [1,2,3].indexOf(5).should.equal(-1); - [1,2,3].indexOf(0).should.equal(-1); +describe('integer primitives', function(){ + describe('arithmetic', function(){ + it('should add', function(){ + expect(1 + 1).to.equal(2); + expect(2 + 2).to.equal(4); }) - it('should return the correct index when the value is present', function(){ - [1,2,3].indexOf(1).should.equal(0); - [1,2,3].indexOf(2).should.equal(1); - [1,2,3].indexOf(3).should.equal(2); + it('should subtract', function(){ + expect(1 - 1).to.equal(0); + expect(2 - 1).to.equal(1); }) }) }) -describe('Array', function(){ - describe('#pop()', function(){ - it('should remove and return the last value', function(){ - var arr = [1,2,3]; - arr.pop().should.equal(3); - arr.should.eql([1,2]); +describe('integer primitives', function(){ + describe('arithmetic is not', function(){ + it('should add', function(){ + expect(1 + 1).not.to.equal(3); + expect(2 + 2).not.to.equal(5); }) }) }) -context('Array', function(){ +context('test suite', function(){ beforeEach(function(){ - this.arr = [1,2,3]; + this.number = 5; }) - specify('has a length property', function(){ - this.arr.length.should.equal(3); + specify('share a property', function(){ + expect(this.number).to.equal(5); }) }) diff --git a/test/acceptance/interfaces/exports.js b/test/acceptance/interfaces/exports.js index 38093d50ea..08db71200b 100644 --- a/test/acceptance/interfaces/exports.js +++ b/test/acceptance/interfaces/exports.js @@ -7,7 +7,7 @@ exports.Array = { after: function(){ calls.push('after'); - calls.should.eql([ + expect(calls).to.eql([ 'before' , 'before each' , 'one' @@ -29,15 +29,15 @@ exports.Array = { 'should return -1 when the value is not present': function(){ calls.push('one'); - [1,2,3].indexOf(5).should.equal(-1); - [1,2,3].indexOf(0).should.equal(-1); + expect([1,2,3].indexOf(5)).to.equal(-1); + expect([1,2,3].indexOf(0)).to.equal(-1); }, 'should return the correct index when the value is present': function(){ calls.push('two'); - [1,2,3].indexOf(1).should.equal(0); - [1,2,3].indexOf(2).should.equal(1); - [1,2,3].indexOf(3).should.equal(2); + expect([1,2,3].indexOf(1)).to.equal(0); + expect([1,2,3].indexOf(2)).to.equal(1); + expect([1,2,3].indexOf(3)).to.equal(2); } } }; diff --git a/test/acceptance/interfaces/qunit.js b/test/acceptance/interfaces/qunit.js index 48aa21d602..d452e769c5 100644 --- a/test/acceptance/interfaces/qunit.js +++ b/test/acceptance/interfaces/qunit.js @@ -2,18 +2,18 @@ function ok(expr, msg) { if (!expr) throw new Error(msg); } -suite('Array'); +suite('integer primitives'); -test('#length', function(){ - var arr = [1,2,3]; - ok(arr.length == 3); +test('should add', function(){ + var number = 2 + 2; + ok(number == 4); }); -test('#indexOf()', function(){ - var arr = [1,2,3]; - ok(arr.indexOf(1) == 0); - ok(arr.indexOf(2) == 1); - ok(arr.indexOf(3) == 2); +test('should decrement', function(){ + var number = 3; + ok(--number == 2); + ok(--number == 1); + ok(--number == 0); }); suite('String'); diff --git a/test/acceptance/interfaces/tdd.js b/test/acceptance/interfaces/tdd.js index 1c6885ed42..7ad079e36d 100644 --- a/test/acceptance/interfaces/tdd.js +++ b/test/acceptance/interfaces/tdd.js @@ -1,40 +1,39 @@ -suite('Array', function(){ - suite('#indexOf()', function(){ - var initialValue = 32; +suite('integer primitives', function(){ + suite('arithmetic', function(){ + var initialValue = 41; suiteSetup(function(done){ - initialValue.should.eql(32); - initialValue = 42; + expect(initialValue).to.eql(41); + initialValue += 1; done(); }); - test('should return -1 when the value is not present', function(){ - initialValue.should.eql(42); - [1,2,3].indexOf(5).should.equal(-1); - [1,2,3].indexOf(0).should.equal(-1); + test('should add', function(){ + expect(initialValue).to.eql(42); + expect(1 + 1).to.equal(2); + expect(2 + 2).to.equal(4); }); - test('should return the correct index when the value is present', function(){ - initialValue.should.eql(42); - [1,2,3].indexOf(1).should.equal(0); - [1,2,3].indexOf(2).should.equal(1); - [1,2,3].indexOf(3).should.equal(2); + test('should subtract', function(){ + expect(initialValue).to.eql(42); + expect(1 - 1).to.equal(0); + expect(2 - 1).to.equal(1); }); test.skip('should skip this test', function(){ var zero = 0; - zero.should.equal(1, 'this test should have been skipped'); + expect(zero).to.equal(1, 'this test should have been skipped'); }); suite.skip('should skip this suite', function(){ test('should skip this test', function(){ var zero = 0; - zero.should.equal(1, 'this test should have been skipped'); + expect(zero).to.equal(1, 'this test should have been skipped'); }); }); suiteTeardown(function(done){ - initialValue.should.eql(42); + expect(initialValue).to.eql(42); done(); }); }); diff --git a/test/acceptance/lookup-files.js b/test/acceptance/lookup-files.js index 453f0de4c7..504d23aab1 100644 --- a/test/acceptance/lookup-files.js +++ b/test/acceptance/lookup-files.js @@ -10,37 +10,35 @@ describe('lookupFiles', function() { }); it('should not choke on symlinks', function() { - utils.lookupFiles('/tmp', ['js'], false) - .should - .containEql('/tmp/mocha-utils-link.js') + expect(utils.lookupFiles('/tmp', ['js'], false)) + .to + .contain('/tmp/mocha-utils-link.js') .and - .containEql('/tmp/mocha-utils.js') + .contain('/tmp/mocha-utils.js') .and .have - .lengthOf(2); - existsSync('/tmp/mocha-utils-link.js') - .should - .be - .true(); + .length(2); + expect(existsSync('/tmp/mocha-utils-link.js')) + .to + .be(true); fs.renameSync('/tmp/mocha-utils.js', '/tmp/bob'); - existsSync('/tmp/mocha-utils-link.js') - .should - .be - .false(); - utils.lookupFiles('/tmp', ['js'], false) - .should + expect(existsSync('/tmp/mocha-utils-link.js')) + .to + .be(false); + expect(utils.lookupFiles('/tmp', ['js'], false)) + .to .eql([]); }); it('should accept a glob "path" value', function() { - utils.lookupFiles('/tmp/mocha-utils*', ['js'], false) - .should - .containEql('/tmp/mocha-utils-link.js') + expect(utils.lookupFiles('/tmp/mocha-utils*', ['js'], false)) + .to + .contain('/tmp/mocha-utils-link.js') .and - .containEql('/tmp/mocha-utils.js') + .contain('/tmp/mocha-utils.js') .and .have - .lengthOf(2); + .length(2); }); afterEach(function() { diff --git a/test/acceptance/misc/only/bdd.js b/test/acceptance/misc/only/bdd.js index ff14dcdfe3..bb05ad9792 100644 --- a/test/acceptance/misc/only/bdd.js +++ b/test/acceptance/misc/only/bdd.js @@ -1,14 +1,14 @@ describe('should only run .only test in this bdd suite', function() { it('should not run this test', function() { var zero = 0; - zero.should.equal(1, 'this test should have been skipped'); + expect(zero).to.equal(1, 'this test should have been skipped'); }); it.only('should run this test', function() { var zero = 0; - zero.should.equal(0, 'this .only test should run'); + expect(zero).to.equal(0, 'this .only test should run'); }); it('should run this test, not (includes the title of the .only test)', function() { var zero = 0; - zero.should.equal(1, 'this test should have been skipped'); + expect(zero).to.equal(1, 'this test should have been skipped'); }); }); diff --git a/test/acceptance/misc/only/tdd.js b/test/acceptance/misc/only/tdd.js index cb6429a3d6..306d06a9f9 100644 --- a/test/acceptance/misc/only/tdd.js +++ b/test/acceptance/misc/only/tdd.js @@ -1,14 +1,14 @@ suite('should only run .only test in this tdd suite', function() { test('should not run this test', function() { var zero = 0; - zero.should.equal(1, 'this test should have been skipped'); + expect(zero).to.equal(1, 'this test should have been skipped'); }); test.only('should run this test', function() { var zero = 0; - zero.should.equal(0, 'this .only test should run'); + expect(zero).to.equal(0, 'this .only test should run'); }); test('should run this test, not (includes the title of the .only test)', function() { var zero = 0; - zero.should.equal(1, 'this test should have been skipped'); + expect(zero).to.equal(1, 'this test should have been skipped'); }); }); diff --git a/test/acceptance/require/require.js b/test/acceptance/require/require.js index 20f3e6d6ef..22570e62ff 100644 --- a/test/acceptance/require/require.js +++ b/test/acceptance/require/require.js @@ -1,9 +1,9 @@ describe('require test', function(){ it('should require args in order', function(){ var req = global.required; - req.indexOf('a.js').should.equal(0); - req.indexOf('b.coffee').should.equal(1); - req.indexOf('c.js').should.equal(2); - req.indexOf('d.coffee').should.equal(3); + expect(req.indexOf('a.js')).to.equal(0); + expect(req.indexOf('b.coffee')).to.equal(1); + expect(req.indexOf('c.js')).to.equal(2); + expect(req.indexOf('d.coffee')).to.equal(3); }) }); diff --git a/test/acceptance/root.js b/test/acceptance/root.js index 17738302da..037e6a328a 100644 --- a/test/acceptance/root.js +++ b/test/acceptance/root.js @@ -6,6 +6,6 @@ before(function(){ describe('root', function(){ it('should be a valid suite', function(){ - calls.should.eql(['before']); + expect(calls).to.eql(['before']); }) }) diff --git a/test/acceptance/test.coffee b/test/acceptance/test.coffee index 8260940a1e..b8e309f515 100644 --- a/test/acceptance/test.coffee +++ b/test/acceptance/test.coffee @@ -3,4 +3,4 @@ obj = foo: 'bar' describe 'coffeescript', -> it 'should work', -> - obj.should.eql foo: 'bar' + expect(obj).to.eql foo: 'bar' diff --git a/test/acceptance/throw.js b/test/acceptance/throw.js index 4665e52ac3..e3fb9d90fb 100644 --- a/test/acceptance/throw.js +++ b/test/acceptance/throw.js @@ -20,8 +20,8 @@ describe('a test that throws', function () { suite.addTest(test); runner = new Runner(suite); runner.on('end', function(){ - runner.failures.should.equal(1); - test.state.should.equal('failed'); + expect(runner.failures).to.equal(1); + expect(test.state).to.equal('failed'); done(); }); runner.run(); @@ -35,8 +35,8 @@ describe('a test that throws', function () { suite.addTest(test); runner = new Runner(suite); runner.on('end', function(){ - runner.failures.should.equal(1); - test.state.should.equal('failed'); + expect(runner.failures).to.equal(1); + expect(test.state).to.equal('failed'); done(); }); runner.run(); @@ -52,8 +52,8 @@ describe('a test that throws', function () { suite.addTest(test); runner = new Runner(suite); runner.on('end', function(){ - runner.failures.should.equal(1); - test.state.should.equal('failed'); + expect(runner.failures).to.equal(1); + expect(test.state).to.equal('failed'); done(); }); runner.run(); @@ -68,8 +68,8 @@ describe('a test that throws', function () { suite.addTest(test); runner = new Runner(suite); runner.on('end', function(){ - runner.failures.should.equal(1); - test.state.should.equal('failed'); + expect(runner.failures).to.equal(1); + expect(test.state).to.equal('failed'); done(); }); runner.run(); @@ -83,8 +83,8 @@ describe('a test that throws', function () { suite.addTest(test); runner = new Runner(suite); runner.on('end', function(){ - runner.failures.should.equal(1); - test.state.should.equal('failed'); + expect(runner.failures).to.equal(1); + expect(test.state).to.equal('failed'); done(); }); runner.run(); @@ -100,8 +100,8 @@ describe('a test that throws', function () { suite.addTest(test); runner = new Runner(suite); runner.on('end', function(){ - runner.failures.should.equal(1); - test.state.should.equal('failed'); + expect(runner.failures).to.equal(1); + expect(test.state).to.equal('failed'); done(); }); runner.run(); diff --git a/test/acceptance/utils.js b/test/acceptance/utils.js index 0c05b246c3..366d2d8579 100644 --- a/test/acceptance/utils.js +++ b/test/acceptance/utils.js @@ -1,4 +1,5 @@ var utils = require('../../lib/utils'); +var toISOString = require('to-iso-string'); describe('lib/utils', function () { describe('clean', function () { @@ -8,7 +9,7 @@ describe('lib/utils', function () { , " var a = 1;" , "}" ].join("\n"); - utils.clean(fn).should.equal("var a = 1;"); + expect(utils.clean(fn)).to.equal("var a = 1;"); }); it("should format a multi line test indented with spaces", function () { @@ -18,7 +19,7 @@ describe('lib/utils', function () { , " var b = 2;" // this one has more spaces , " var c = 3; }" ].join("\n"); - utils.clean(fn).should.equal("var a = 1;\n var b = 2;\nvar c = 3;"); + expect(utils.clean(fn)).to.equal("var a = 1;\n var b = 2;\nvar c = 3;"); }); it("should format a multi line test indented with tabs", function () { @@ -29,7 +30,7 @@ describe('lib/utils', function () { , "\t}" , "}" ].join("\n"); - utils.clean(fn).should.equal("if (true) {\n\tvar a = 1;\n}"); + expect(utils.clean(fn)).to.equal("if (true) {\n\tvar a = 1;\n}"); }); it("should format functions saved in windows style - spaces", function () { @@ -40,7 +41,7 @@ describe('lib/utils', function () { , " } while (false);" , ' }' ].join("\r\n"); - utils.clean(fn).should.equal('do {\n "nothing";\n} while (false);'); + expect(utils.clean(fn)).to.equal('do {\n "nothing";\n} while (false);'); }); it("should format functions saved in windows style - tabs", function () { @@ -53,7 +54,7 @@ describe('lib/utils', function () { , "\t}" , "}" ].join("\r\n"); - utils.clean(fn).should.equal("if (false) {\n\tvar json = {\n\t\tone : 1\n\t};\n}"); + expect(utils.clean(fn)).to.equal("if (false) {\n\tvar json = {\n\t\tone : 1\n\t};\n}"); }); it("should format es6 arrow functions", function () { @@ -62,12 +63,12 @@ describe('lib/utils', function () { " var a = 1;", "}" ].join("\n"); - utils.clean(fn).should.equal("var a = 1;"); + expect(utils.clean(fn)).to.equal("var a = 1;"); }); it("should format es6 arrow functions with implicit return", function () { var fn = "() => foo()"; - utils.clean(fn).should.equal("foo()"); + expect(utils.clean(fn)).to.equal("foo()"); }); }); @@ -76,40 +77,48 @@ describe('lib/utils', function () { var stringify = utils.stringify; it('should return Buffer with .toJSON representation', function() { - stringify(new Buffer([0x01])).should.equal('[\n 1\n]'); - stringify(new Buffer([0x01, 0x02])).should.equal('[\n 1\n 2\n]'); + expect(stringify(new Buffer([0x01]))).to.equal('[\n 1\n]'); + expect(stringify(new Buffer([0x01, 0x02]))).to.equal('[\n 1\n 2\n]'); - stringify(new Buffer('ABCD')).should.equal('[\n 65\n 66\n 67\n 68\n]'); + expect(stringify(new Buffer('ABCD'))).to.equal('[\n 65\n 66\n 67\n 68\n]'); }); it('should return Date object with .toISOString() + string prefix', function() { - stringify(new Date(0)).should.equal('[Date: ' + new Date(0).toISOString() + ']'); + expect(stringify(new Date(0))).to.equal('[Date: ' + shimToISOString(new Date(0)) + ']'); var date = new Date(); // now - stringify(date).should.equal('[Date: ' + date.toISOString() + ']'); + expect(stringify(date)).to.equal('[Date: ' + shimToISOString(date) + ']'); + + function shimToISOString(date) { + if (date.toISOString) { + return date.toISOString(); + } else { + return toISOString(date); + } + } }); it('should return invalid Date object with .toString() + string prefix', function() { - stringify(new Date('')).should.equal('[Date: ' + new Date('').toString() + ']'); + expect(stringify(new Date(''))).to.equal('[Date: ' + new Date('').toString() + ']'); }); describe('#Number', function() { it('should show the handle -0 situations', function() { - stringify(-0).should.eql('-0'); - stringify(0).should.eql('0'); - stringify('-0').should.eql('"-0"'); + expect(stringify(-0)).to.eql('-0'); + expect(stringify(0)).to.eql('0'); + expect(stringify('-0')).to.eql('"-0"'); }); it('should work well with `NaN` and `Infinity`', function() { - stringify(NaN).should.equal('NaN'); - stringify(Infinity).should.equal('Infinity'); - stringify(-Infinity).should.equal('-Infinity'); + expect(stringify(NaN)).to.equal('NaN'); + expect(stringify(Infinity)).to.equal('Infinity'); + expect(stringify(-Infinity)).to.equal('-Infinity'); }); it('floats and ints', function() { - stringify(1).should.equal('1'); - stringify(1.2).should.equal('1.2'); - stringify(1e9).should.equal('1000000000'); + expect(stringify(1)).to.equal('1'); + expect(stringify(1.2)).to.equal('1.2'); + expect(stringify(1e9)).to.equal('1000000000'); }); }); @@ -184,7 +193,7 @@ describe('lib/utils', function () { , ' "undef": [undefined]' , ' "zero": -0' , '}'].join('\n'); - stringify(expected).should.equal(actual); + expect(stringify(expected)).to.equal(actual); }); }); @@ -192,28 +201,28 @@ describe('lib/utils', function () { var travis = { name: 'travis', age: 24 }; var travis2 = { age: 24, name: 'travis' }; - stringify(travis).should.equal(stringify(travis2)); + expect(stringify(travis)).to.equal(stringify(travis2)); }); it('should handle circular structures in objects', function(){ var travis = { name: 'travis' }; travis.whoami = travis; - stringify(travis).should.equal('{\n "name": "travis"\n "whoami": [Circular]\n}'); + expect(stringify(travis)).to.equal('{\n "name": "travis"\n "whoami": [Circular]\n}'); }); it('should handle circular structures in arrays', function(){ var travis = ['travis']; travis.push(travis); - stringify(travis).should.equal('[\n "travis"\n [Circular]\n]'); + expect(stringify(travis)).to.equal('[\n "travis"\n [Circular]\n]'); }); it('should handle circular structures in functions', function(){ var travis = function () {}; travis.fn = travis; - stringify(travis).should.equal('{\n "fn": [Circular]\n}'); + expect(stringify(travis)).to.equal('{\n "fn": [Circular]\n}'); }); @@ -222,46 +231,44 @@ describe('lib/utils', function () { regExpObj = { regexp: regexp }, regexpString = '/(?:)/'; - stringify(regExpObj).should.equal('{\n "regexp": ' + regexpString + '\n}'); - stringify(regexp).should.equal(regexpString); + expect(stringify(regExpObj)).to.equal('{\n "regexp": ' + regexpString + '\n}'); + expect(stringify(regexp)).to.equal(regexpString); var number = 1, numberObj = { number: number }, numberString = '1'; - stringify(numberObj).should.equal('{\n "number": ' + number + '\n}'); - stringify(number).should.equal(numberString); + expect(stringify(numberObj)).to.equal('{\n "number": ' + number + '\n}'); + expect(stringify(number)).to.equal(numberString); var boolean = false, booleanObj = { boolean: boolean }, booleanString = 'false'; - stringify(booleanObj).should.equal('{\n "boolean": ' + boolean + '\n}'); - stringify(boolean).should.equal(booleanString); + expect(stringify(booleanObj)).to.equal('{\n "boolean": ' + boolean + '\n}'); + expect(stringify(boolean)).to.equal(booleanString); var string = 'sneepy', stringObj = { string: string }; - stringify(stringObj).should.equal('{\n "string": "' + string + '"\n}'); - stringify(string).should.equal(JSON.stringify(string)); + expect(stringify(stringObj)).to.equal('{\n "string": "' + string + '"\n}'); + expect(stringify(string)).to.equal(JSON.stringify(string)); var nullValue = null, nullObj = { 'null': null }, nullString = '[null]'; - stringify(nullObj).should.equal('{\n "null": [null]\n}'); - stringify(nullValue).should.equal(nullString); + expect(stringify(nullObj)).to.equal('{\n "null": [null]\n}'); + expect(stringify(nullValue)).to.equal(nullString); }); it('should handle arrays', function () { var array = ['dave', 'dave', 'dave', 'dave'], arrayObj = {array: array}, - arrayString = array.map(function () { - return ' "dave"'; - }).join('\n'); + arrayString = ' "dave"\n "dave"\n "dave"\n "dave"' - stringify(arrayObj).should.equal('{\n "array": [\n' + arrayString + '\n ]\n}'); - stringify(array).should.equal('[' + arrayString.replace(/\s+/g, '\n ') + '\n]'); + expect(stringify(arrayObj)).to.equal('{\n "array": [\n' + arrayString + '\n ]\n}'); + expect(stringify(array)).to.equal('[' + arrayString.replace(/\s+/g, '\n ') + '\n]'); }); it('should handle functions', function () { @@ -269,80 +276,86 @@ describe('lib/utils', function () { fnObj = {fn: fn}, fnString = '[Function]'; - stringify(fnObj).should.equal('{\n "fn": ' + fnString + '\n}'); - stringify(fn).should.equal('[Function]'); + expect(stringify(fnObj)).to.equal('{\n "fn": ' + fnString + '\n}'); + expect(stringify(fn)).to.equal('[Function]'); }); it('should handle empty objects', function () { - stringify({}).should.equal('{}'); - stringify({foo: {}}).should.equal('{\n "foo": {}\n}'); + expect(stringify({})).to.equal('{}'); + expect(stringify({foo: {}})).to.equal('{\n "foo": {}\n}'); }); it('should handle empty arrays', function () { - stringify([]).should.equal('[]'); - stringify({foo: []}).should.equal('{\n "foo": []\n}'); + expect(stringify([])).to.equal('[]'); + expect(stringify({foo: []})).to.equal('{\n "foo": []\n}'); }); it('should handle non-empty arrays', function () { - stringify(['a', 'b', 'c']).should.equal('[\n "a"\n "b"\n "c"\n]') + expect(stringify(['a', 'b', 'c'])).to.equal('[\n "a"\n "b"\n "c"\n]') }); it('should handle empty functions (with no properties)', function () { - stringify(function(){}).should.equal('[Function]'); - stringify({foo: function() {}}).should.equal('{\n "foo": [Function]\n}'); - stringify({foo: function() {}, bar: 'baz'}).should.equal('{\n "bar": "baz"\n "foo": [Function]\n}'); + expect(stringify(function(){})).to.equal('[Function]'); + expect(stringify({foo: function() {}})).to.equal('{\n "foo": [Function]\n}'); + expect(stringify({foo: function() {}, bar: 'baz'})).to.equal('{\n "bar": "baz"\n "foo": [Function]\n}'); }); it('should handle functions w/ properties', function () { var fn = function(){}; fn.bar = 'baz'; - stringify(fn).should.equal('{\n "bar": "baz"\n}'); - stringify({foo: fn}).should.equal('{\n "foo": {\n "bar": "baz"\n }\n}'); + expect(stringify(fn)).to.equal('{\n "bar": "baz"\n}'); + expect(stringify({foo: fn})).to.equal('{\n "foo": {\n "bar": "baz"\n }\n}'); }); it('should handle undefined values', function () { - stringify({foo: undefined}).should.equal('{\n "foo": [undefined]\n}'); - stringify({foo: 'bar', baz: undefined}).should.equal('{\n "baz": [undefined]\n "foo": "bar"\n}'); - stringify().should.equal('[undefined]'); + expect(stringify({foo: undefined})).to.equal('{\n "foo": [undefined]\n}'); + expect(stringify({foo: 'bar', baz: undefined})).to.equal('{\n "baz": [undefined]\n "foo": "bar"\n}'); + expect(stringify()).to.equal('[undefined]'); }); it('should recurse', function () { - stringify({foo: {bar: {baz: {quux: {herp: 'derp'}}}}}).should.equal('{\n "foo": {\n "bar": {\n "baz": {\n "quux": {\n "herp": "derp"\n }\n }\n }\n }\n}'); + expect(stringify({foo: {bar: {baz: {quux: {herp: 'derp'}}}}})).to.equal('{\n "foo": {\n "bar": {\n "baz": {\n "quux": {\n "herp": "derp"\n }\n }\n }\n }\n}'); }); it('might get confusing', function () { - stringify(null).should.equal('[null]'); + expect(stringify(null)).to.equal('[null]'); }); it('should not freak out if it sees a primitive twice', function () { - stringify({foo: null, bar: null}).should.equal('{\n "bar": [null]\n "foo": [null]\n}'); - stringify({foo: 1, bar: 1}).should.equal('{\n "bar": 1\n "foo": 1\n}'); + expect(stringify({foo: null, bar: null})).to.equal('{\n "bar": [null]\n "foo": [null]\n}'); + expect(stringify({foo: 1, bar: 1})).to.equal('{\n "bar": 1\n "foo": 1\n}'); }); it('should stringify dates', function () { var date = new Date(0); - stringify(date).should.equal('[Date: 1970-01-01T00:00:00.000Z]'); - stringify({date: date}).should.equal('{\n "date": [Date: 1970-01-01T00:00:00.000Z]\n}'); + expect(stringify(date)).to.equal('[Date: 1970-01-01T00:00:00.000Z]'); + expect(stringify({date: date})).to.equal('{\n "date": [Date: 1970-01-01T00:00:00.000Z]\n}'); }); it('should handle object without an Object prototype', function () { - var a = Object.create(null); + var a; + if (Object.create) { + a = Object.create(null); + } else { + a = {}; + } a.foo = 1; - stringify(a).should.equal('{\n "foo": 1\n}'); + expect(stringify(a)).to.equal('{\n "foo": 1\n}'); }); // In old version node.js, Symbol is not available by default. if (typeof global.Symbol === 'function') { it('should handle Symbol', function () { var symbol = Symbol('value'); - stringify(symbol).should.equal('Symbol(value)'); - stringify({symbol: symbol}).should.equal('{\n "symbol": Symbol(value)\n}') + expect(stringify(symbol)).to.equal('Symbol(value)'); + expect(stringify({symbol: symbol})).to.equal('{\n "symbol": Symbol(value)\n}') }); } it('should handle length properties that cannot be coerced to a number', function () { - stringify({length: {toString: 0}}).should.equal('{\n "length": {\n "toString": 0\n }\n}'); + expect(stringify({length: {nonBuiltinProperty: 0}})).to.equal('{\n "length": {\n "nonBuiltinProperty": 0\n }\n}'); + expect(stringify({length: "a string where length should be"})).to.equal('{\n "length": "a string where length should be"\n}'); }); }); @@ -361,23 +374,23 @@ describe('lib/utils', function () { }); it('should recognize various types', function () { - type({}).should.equal('object'); - type([]).should.equal('array'); - type(1).should.equal('number'); - type(Infinity).should.equal('number'); - type(null).should.equal('null'); - type(undefined).should.equal('undefined'); - type(new Date()).should.equal('date'); - type(/foo/).should.equal('regexp'); - type('type').should.equal('string'); - type(global).should.equal('domwindow'); - type(true).should.equal('boolean'); + expect(type({})).to.equal('object'); + expect(type([])).to.equal('array'); + expect(type(1)).to.equal('number'); + expect(type(Infinity)).to.equal('number'); + expect(type(null)).to.equal('null'); + expect(type(undefined)).to.equal('undefined'); + expect(type(new Date())).to.equal('date'); + expect(type(/foo/)).to.equal('regexp'); + expect(type('type')).to.equal('string'); + expect(type(global)).to.equal('domwindow'); + expect(type(true)).to.equal('boolean'); }); describe('when toString on null or undefined stringifies window', function () { it('should recognize null and undefined', function () { - type(null).should.equal('null'); - type(undefined).should.equal('undefined'); + expect(type(null)).to.equal('null'); + expect(type(undefined)).to.equal('undefined'); }); }); diff --git a/test/fixture-expect.js b/test/fixture-expect.js new file mode 100644 index 0000000000..cacc78425a --- /dev/null +++ b/test/fixture-expect.js @@ -0,0 +1 @@ +global.expect = require("expect.js") diff --git a/test/mocha.opts b/test/mocha.opts index 3c2f2cbd02..cd797e2ae0 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1,4 +1,5 @@ --require should +--require ./test/fixture-expect.js --reporter dot --ui bdd --globals okGlobalA,okGlobalB