This repository has been archived by the owner on Dec 4, 2023. It is now read-only.
forked from mochajs/mocha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiple-done.spec.js
130 lines (114 loc) · 3.69 KB
/
multiple-done.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
'use strict';
var assert = require('assert');
var run = require('./helpers').runMochaJSON;
var args = [];
describe('multiple calls to done()', function() {
var res;
describe('from a spec', function() {
before(function(done) {
run('multiple-done.fixture.js', args, function(err, result) {
res = result;
done(err);
});
});
it('results in failures', function() {
assert.strictEqual(res.stats.pending, 0, 'wrong "pending" count');
assert.strictEqual(res.stats.passes, 1, 'wrong "passes" count');
assert.strictEqual(res.stats.failures, 1, 'wrong "failures" count');
});
it('throws a descriptive error', function() {
assert.strictEqual(
res.failures[0].err.message,
'done() called multiple times'
);
});
});
describe('with error passed on second call', function() {
before(function(done) {
run('multiple-done-with-error.fixture.js', args, function(err, result) {
res = result;
done(err);
});
});
it('results in failures', function() {
assert.strictEqual(res.stats.pending, 0, 'wrong "pending" count');
assert.strictEqual(res.stats.passes, 1, 'wrong "passes" count');
assert.strictEqual(res.stats.failures, 1, 'wrong "failures" count');
});
it('should throw a descriptive error', function() {
assert.strictEqual(
res.failures[0].err.message,
"second error (and Mocha's done() called multiple times)"
);
});
});
describe('with multiple specs', function() {
before(function(done) {
run('multiple-done-specs.fixture.js', args, function(err, result) {
res = result;
done(err);
});
});
it('results in a failure', function() {
assert.strictEqual(res.stats.pending, 0);
assert.strictEqual(res.stats.passes, 2);
assert.strictEqual(res.stats.failures, 1);
assert.strictEqual(res.code, 1);
});
it('correctly attributes the error', function() {
assert.strictEqual(res.failures[0].fullTitle, 'suite test1');
assert.strictEqual(
res.failures[0].err.message,
'done() called multiple times'
);
});
});
describe('from a before hook', function() {
before(function(done) {
run('multiple-done-before.fixture.js', args, function(err, result) {
res = result;
done(err);
});
});
it('results in a failure', function() {
assert.strictEqual(res.stats.pending, 0);
assert.strictEqual(res.stats.passes, 1);
assert.strictEqual(res.stats.failures, 1);
assert.strictEqual(res.code, 1);
});
it('correctly attributes the error', function() {
assert.strictEqual(
res.failures[0].fullTitle,
'suite "before all" hook in "suite"'
);
assert.strictEqual(
res.failures[0].err.message,
'done() called multiple times'
);
});
});
describe('from a beforeEach hook', function() {
before(function(done) {
run('multiple-done-beforeEach.fixture.js', args, function(err, result) {
res = result;
done(err);
});
});
it('results in a failure', function() {
assert.strictEqual(res.stats.pending, 0);
assert.strictEqual(res.stats.passes, 2);
assert.strictEqual(res.stats.failures, 2);
assert.strictEqual(res.code, 2);
});
it('correctly attributes the errors', function() {
assert.strictEqual(res.failures.length, 2);
res.failures.forEach(function(failure) {
assert.strictEqual(
failure.fullTitle,
'suite "before each" hook in "suite"'
);
assert.strictEqual(failure.err.message, 'done() called multiple times');
});
});
});
});