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
/
bail.spec.js
134 lines (117 loc) · 3.83 KB
/
bail.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
131
132
133
134
'use strict';
var path = require('path').posix;
var helpers = require('../helpers');
var runMochaJSON = helpers.runMochaJSON;
describe('--bail', function() {
var args = [];
before(function() {
args = ['--bail'];
});
it('should stop after the first error', function(done) {
var fixture = path.join('options', 'bail');
runMochaJSON(fixture, args, function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have failed')
.and('to have passed test', 'should display this spec')
.and('to have failed test', 'should only display this error')
.and('to have passed test count', 1)
.and('to have failed test count', 1);
done();
});
});
it('should stop after the first error - async', function(done) {
var fixture = path.join('options', 'bail-async');
runMochaJSON(fixture, args, function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have failed')
.and('to have passed test', 'should display this spec')
.and('to have failed test', 'should only display this error')
.and('to have passed test count', 1)
.and('to have failed test count', 1);
done();
});
});
it('should stop all tests after failing "before" hook', function(done) {
var fixture = path.join('options', 'bail-with-before');
runMochaJSON(fixture, args, function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have failed')
.and('to have failed test count', 1)
.and(
'to have failed test',
'"before all" hook: before suite1 for "test suite1"'
)
.and('to have passed test count', 0);
done();
});
});
it('should stop all tests after failing "beforeEach" hook', function(done) {
var fixture = path.join('options', 'bail-with-beforeEach');
runMochaJSON(fixture, args, function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have failed')
.and('to have failed test count', 1)
.and(
'to have failed test',
'"before each" hook: beforeEach suite1 for "test suite1"'
)
.and('to have passed test count', 0);
done();
});
});
it('should stop all tests after failing test', function(done) {
var fixture = path.join('options', 'bail-with-test');
runMochaJSON(fixture, args, function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have failed')
.and('to have failed test count', 1)
.and('to have failed test', 'test suite1')
.and('to have passed test count', 0);
done();
});
});
it('should stop all tests after failing "after" hook', function(done) {
var fixture = path.join('options', 'bail-with-after');
runMochaJSON(fixture, args, function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have failed')
.and('to have failed test count', 1)
.and(
'to have failed test',
'"after all" hook: after suite1A for "test suite1A"'
)
.and('to have passed test count', 2)
.and('to have passed test order', 'test suite1', 'test suite1A');
done();
});
});
it('should stop all tests after failing "afterEach" hook', function(done) {
var fixture = path.join('options', 'bail-with-afterEach');
runMochaJSON(fixture, args, function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have failed')
.and('to have failed test count', 1)
.and(
'to have failed test',
'"after each" hook: afterEach suite1A for "test suite1A"'
)
.and('to have passed test count', 2)
.and('to have passed test order', 'test suite1', 'test suite1A');
done();
});
});
});