Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Hiller <boneskull@boneskull.com>
  • Loading branch information
boneskull committed May 19, 2020
1 parent 770659d commit 55283e3
Showing 1 changed file with 80 additions and 32 deletions.
112 changes: 80 additions & 32 deletions test/unit/runner.spec.js
Expand Up @@ -10,6 +10,7 @@ var Test = Mocha.Test;
var Runnable = Mocha.Runnable;
var Hook = Mocha.Hook;
var noop = Mocha.utils.noop;
var errors = require('../../lib/errors');
var EVENT_HOOK_BEGIN = Runner.constants.EVENT_HOOK_BEGIN;
var EVENT_TEST_FAIL = Runner.constants.EVENT_TEST_FAIL;
var EVENT_TEST_RETRY = Runner.constants.EVENT_TEST_RETRY;
Expand Down Expand Up @@ -255,16 +256,16 @@ describe('Runner', function() {
});
});

describe('.fail(test, err)', function() {
it('should increment .failures', function() {
describe('fail()', function() {
it('should increment `Runner#failures`', function() {
expect(runner.failures, 'to be', 0);
runner.fail(new Test('one', noop), {});
expect(runner.failures, 'to be', 1);
runner.fail(new Test('two', noop), new Error());
expect(runner.failures, 'to be', 2);
});

it('should set test.state to "failed"', function() {
it('should set `Test#state` to "failed"', function() {
var test = new Test('some test', noop);
runner.fail(test, 'some error');
expect(test.state, 'to be', STATE_FAILED);
Expand Down Expand Up @@ -376,6 +377,47 @@ describe('Runner', function() {
runner.fail(test, new Error());
expect(runner.failures, 'to be', 0);
});

describe('when Runner has stopped', function() {
beforeEach(function() {
runner.state = STATE_STOPPED;
});

describe('when test is not pending', function() {
describe('when error is the "multiple done" variety', function() {
it('should throw the "multiple done" error', function() {
var test = new Test('test', function() {});
suite.addTest(test);
var err = new Error();
err.code = errors.constants.MULTIPLE_DONE;
expect(
function() {
runner.fail(test, err);
},
'to throw',
err
);
});
});

describe('when error is not of the "multiple done" variety', function() {
it('should throw a "fatal" error', function() {
var test = new Test('test', function() {});
suite.addTest(test);
var err = new Error();
expect(
function() {
runner.fail(test, err);
},
'to throw',
{
code: errors.constants.FATAL
}
);
});
});
});
});
});

describe('.failHook(hook, err)', function() {
Expand Down Expand Up @@ -852,7 +894,7 @@ describe('Runner', function() {
]).and('was called once');
});

describe('when Runner has already started', function() {
describe('when Runner is RUNNING', function() {
beforeEach(function() {
runner.state = STATE_RUNNING;
});
Expand All @@ -869,39 +911,45 @@ describe('Runner', function() {
});
});

describe('when Runner not running', function() {
describe('when idle', function() {
beforeEach(function() {
runner.state = STATE_IDLE;
});
describe('when Runner is IDLE', function() {
beforeEach(function() {
runner.state = STATE_IDLE;
});

it('should emit start/end events for the benefit of reporters', function() {
expect(
function() {
runner.uncaught(err);
},
'to emit from',
runner,
'start'
).and('to emit from', runner, 'end');
});
it('should emit start/end events for the benefit of reporters', function() {
expect(
function() {
runner.uncaught(err);
},
'to emit from',
runner,
'start'
).and('to emit from', runner, 'end');
});
});

describe('when stopped', function() {
beforeEach(function() {
runner.state = STATE_STOPPED;
});
describe('when Runner is STOPPED', function() {
beforeEach(function() {
runner.state = STATE_STOPPED;
});

it('should emit start/end events for the benefit of reporters', function() {
expect(
function() {
it('should not emit start/end events, since this presumably would have already happened', function() {
expect(
function() {
try {
runner.uncaught(err);
},
'to emit from',
runner,
'start'
).and('to emit from', runner, 'end');
});
} catch (ignored) {}
},
'not to emit from',
runner,
'start'
).and('not to emit from', runner, 'end');
});

it('should throw', function() {
expect(function() {
runner.uncaught(err);
}, 'to throw');
});
});
});
Expand Down

0 comments on commit 55283e3

Please sign in to comment.