Skip to content

Commit

Permalink
adapt existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba committed Jan 13, 2020
1 parent b599ab2 commit 68727a8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 85 deletions.
5 changes: 4 additions & 1 deletion test/integration/hook-err.spec.js
Expand Up @@ -194,7 +194,10 @@ describe('hook error handling', function() {
run('hooks/before-hook-async-error-tip.fixture.js', onlyErrorTitle())
);
it('should verify results', function() {
expect(lines, 'to equal', ['1) spec 2', '"before all" hook:']);
expect(lines, 'to equal', [
'1) spec 2',
'"before all" hook for "skipped":'
]);
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/integration/uncaught.spec.js
Expand Up @@ -17,7 +17,7 @@ describe('uncaught exceptions', function() {

assert.strictEqual(
res.failures[0].fullTitle,
'uncaught "before each" hook'
'uncaught "before each" hook for "test"'
);
assert.strictEqual(res.code, 1);
done();
Expand Down
105 changes: 22 additions & 83 deletions test/unit/runner.spec.js
Expand Up @@ -783,14 +783,9 @@ describe('Runner', function() {
runnable.parent = runner.suite;
sandbox.stub(runnable, 'clearTimeout');
runner.currentRunnable = runnable;
runner.nextSuite = sandbox.spy();
});

afterEach(function() {
delete runner.nextSuite;
});

it('should clear any pending timeouts', function() {
it.skip('should clear any pending timeouts', function() {
runner.uncaught(err);
expect(runnable.clearTimeout, 'was called times', 1);
});
Expand Down Expand Up @@ -844,75 +839,39 @@ describe('Runner', function() {
});
});

describe('when the current Runnable is currently running', function() {
describe('when the current Runnable is still running', function() {
describe('when the current Runnable is a Test', function() {
beforeEach(function() {
runnable = new Test('goomba', noop);
runnable.parent = runner.suite;
runner.currentRunnable = runnable;
sandbox.stub(runner, 'hookUp');
runner.next = sandbox.spy();
runnable.callback = sandbox.fake();
});

afterEach(function() {
delete runner.next;
delete runnable.callback;
});

it('should fail with the current Runnable and the error', function() {
it('should run callback(err) to handle failing and hooks', function() {
runner.uncaught(err);

expect(runner.fail, 'to have all calls satisfying', [
expect.it('to be', runnable),
expect(runner.fail, 'was not called');
expect(runnable.callback, 'to have all calls satisfying', [
err
]).and('was called once');
});

it('should notify test has ended', function() {
expect(
function() {
runner.uncaught(err);
},
'to emit from',
runner,
'test end',
runnable
);
});

it('should not notify run has ended', function() {
it('should not notify test has ended', function() {
expect(
function() {
runner.uncaught(err);
},
'not to emit from',
runner,
'end'
'test end'
);
});

it('should call any remaining "after each" hooks', function() {
runner.uncaught(err);
expect(runner.hookUp, 'to have all calls satisfying', [
'afterEach',
expect.it('to be', runner.next)
]).and('was called once');
});
});

describe('when the current Runnable is a "before all" or "after all" hook', function() {
beforeEach(function() {
runnable = new Hook('', noop);
runnable.parent = runner.suite;
runner.currentRunnable = runnable;
});

it('should continue to the next suite', function() {
runner.uncaught(err);
expect(runner.nextSuite, 'to have all calls satisfying', [
runner.suite
]).and('was called once');
});

it('should not notify run has ended', function() {
expect(
function() {
Expand All @@ -925,59 +884,39 @@ describe('Runner', function() {
});
});

describe('when the current Runnable is a "before each" hook', function() {
describe('when the current Runnable is a Hook', function() {
beforeEach(function() {
runnable = new Hook('before each', noop);
runnable = new Hook();
runnable.parent = runner.suite;
runner.currentRunnable = runnable;
runner.hookErr = sandbox.spy();
runner.next = sandbox.spy();
runnable.callback = sandbox.fake();
});

afterEach(function() {
delete runner.hookErr;
delete runner.next;
delete runnable.callback;
});

it('should associate its failure with the current test', function() {
it('should run callback(err) to handle failing hook pattern', function() {
runner.uncaught(err);
expect(runner.hookErr, 'to have all calls satisfying', [
err,
runner.suite,
false

expect(runner.fail, 'was not called');
expect(runnable.callback, 'to have all calls satisfying', [
err
]).and('was called once');
});

it('should not notify run has ended', function() {
it('should not notify test has ended', function() {
expect(
function() {
runner.uncaught(err);
},
'not to emit from',
runner,
'end'
'test end'
);
});
});

describe('when the current Runnable is an "after each" hook', function() {
beforeEach(function() {
runnable = new Hook('after each', noop);
runnable.parent = runner.suite;
runner.currentRunnable = runnable;
runner.hookErr = sandbox.spy();
});

afterEach(function() {
delete runner.hookErr;
});

it('should associate its failure with the current test', function() {
runner.uncaught(err);
expect(runner.hookErr, 'to have all calls satisfying', [
err,
runner.suite,
true
]).and('was called once');
});

it('should not notify run has ended', function() {
expect(
Expand Down

0 comments on commit 68727a8

Please sign in to comment.