diff options
Diffstat (limited to 'tests/lib/mocha-3.1.2/test/acceptance/throw.spec.js')
-rw-r--r-- | tests/lib/mocha-3.1.2/test/acceptance/throw.spec.js | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/tests/lib/mocha-3.1.2/test/acceptance/throw.spec.js b/tests/lib/mocha-3.1.2/test/acceptance/throw.spec.js new file mode 100644 index 0000000000..68e8cd2c1d --- /dev/null +++ b/tests/lib/mocha-3.1.2/test/acceptance/throw.spec.js @@ -0,0 +1,108 @@ +'use strict'; + +/* eslint no-throw-literal: off */ + +var Suite = require('../../lib/suite'); +var Test = require('../../lib/test'); +var Runner = require('../../lib/runner'); + +describe('a test that throws', function () { + var suite, runner; + + beforeEach(function () { + suite = new Suite('Suite', 'root'); + runner = new Runner(suite); + }); + + describe('undefined', function () { + it('should not pass if throwing sync and test is sync', function (done) { + var test = new Test('im sync and throw undefined sync', function () { + throw undefined; + }); + suite.addTest(test); + runner = new Runner(suite); + runner.on('end', function () { + expect(runner.failures).to.equal(1); + expect(test.state).to.equal('failed'); + done(); + }); + runner.run(); + }); + + it('should not pass if throwing sync and test is async', function (done) { + var test = new Test('im async and throw undefined sync', function (done2) { + throw undefined; + }); + suite.addTest(test); + runner = new Runner(suite); + runner.on('end', function () { + expect(runner.failures).to.equal(1); + expect(test.state).to.equal('failed'); + done(); + }); + runner.run(); + }); + + it('should not pass if throwing async and test is async', function (done) { + var test = new Test('im async and throw undefined async', function (done2) { + process.nexTick(function () { + throw undefined; + }); + }); + suite.addTest(test); + runner = new Runner(suite); + runner.on('end', function () { + expect(runner.failures).to.equal(1); + expect(test.state).to.equal('failed'); + done(); + }); + runner.run(); + }); + }); + + describe('null', function () { + it('should not pass if throwing sync and test is sync', function (done) { + var test = new Test('im sync and throw null sync', function () { + throw null; + }); + suite.addTest(test); + runner = new Runner(suite); + runner.on('end', function () { + expect(runner.failures).to.equal(1); + expect(test.state).to.equal('failed'); + done(); + }); + runner.run(); + }); + + it('should not pass if throwing sync and test is async', function (done) { + var test = new Test('im async and throw null sync', function (done2) { + throw null; + }); + suite.addTest(test); + runner = new Runner(suite); + runner.on('end', function () { + expect(runner.failures).to.equal(1); + expect(test.state).to.equal('failed'); + done(); + }); + runner.run(); + }); + + it('should not pass if throwing async and test is async', function (done) { + var test = new Test('im async and throw null async', function (done2) { + process.nexTick(function () { + throw null; + }); + }); + suite.addTest(test); + runner = new Runner(suite); + runner.on('end', function () { + expect(runner.failures).to.equal(1); + expect(test.state).to.equal('failed'); + done(); + }); + runner.run(); + }); + }); +}); |