-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
uncaught.spec.js
63 lines (55 loc) · 1.79 KB
/
uncaught.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict';
var assert = require('assert');
var run = require('./helpers').runMochaJSON;
var args = [];
describe('uncaught exceptions', function () {
it('handles uncaught exceptions from hooks', function (done) {
run('uncaught-hook.fixture.js', args, function (err, res) {
if (err) {
done(err);
return;
}
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 0);
assert.equal(res.stats.failures, 1);
assert.equal(res.failures[0].fullTitle,
'uncaught "before each" hook');
assert.equal(res.code, 1);
done();
});
});
it('handles uncaught exceptions from async specs', function (done) {
run('uncaught.fixture.js', args, function (err, res) {
if (err) {
done(err);
return;
}
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 0);
assert.equal(res.stats.failures, 2);
assert.equal(res.failures[0].title,
'fails exactly once when a global error is thrown first');
assert.equal(res.failures[1].title,
'fails exactly once when a global error is thrown second');
assert.equal(res.code, 2);
done();
});
});
it('handles uncaught exceptions from which Mocha cannot recover', function (done) {
run('uncaught-fatal.fixture.js', args, function (err, res) {
if (err) {
done(err);
return;
}
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 1);
assert.equal(res.stats.failures, 1);
assert.equal(res.failures[0].title,
'should bail if a successful test asynchronously fails');
assert.equal(res.passes[0].title,
'should bail if a successful test asynchronously fails');
assert.equal(res.code, 1);
done();
});
});
});