forked from mochajs/mocha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec.spec.js
161 lines (145 loc) · 4.31 KB
/
spec.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
'use strict';
var sinon = require('sinon');
var events = require('../../').Runner.constants;
var helpers = require('./helpers');
var reporters = require('../../').reporters;
var Base = reporters.Base;
var Spec = reporters.Spec;
var createMockRunner = helpers.createMockRunner;
var makeRunReporter = helpers.createRunReporterFunction;
var EVENT_SUITE_BEGIN = events.EVENT_SUITE_BEGIN;
var EVENT_TEST_FAIL = events.EVENT_TEST_FAIL;
var EVENT_TEST_PASS = events.EVENT_TEST_PASS;
var EVENT_TEST_PENDING = events.EVENT_TEST_PENDING;
describe('Spec reporter', function () {
var runReporter = makeRunReporter(Spec);
var expectedTitle = 'expectedTitle';
var noop = function () {};
beforeEach(function () {
sinon.stub(Base, 'useColors').value(false);
});
afterEach(function () {
sinon.restore();
});
describe('event handlers', function () {
describe("on 'suite' event", function () {
it('should return title', function () {
var suite = {
title: expectedTitle
};
var runner = createMockRunner(
'suite',
EVENT_SUITE_BEGIN,
null,
null,
suite
);
var options = {};
var stdout = runReporter({epilogue: noop}, runner, options);
sinon.restore();
var expectedArray = [expectedTitle + '\n'];
expect(stdout, 'to equal', expectedArray);
});
});
describe("on 'pending' event", function () {
it('should return title', function () {
var suite = {
title: expectedTitle
};
var runner = createMockRunner(
'pending test',
EVENT_TEST_PENDING,
null,
null,
suite
);
var options = {};
var stdout = runReporter({epilogue: noop}, runner, options);
sinon.restore();
var expectedArray = [' - ' + expectedTitle + '\n'];
expect(stdout, 'to equal', expectedArray);
});
});
describe("on 'pass' event", function () {
describe('when test speed is slow', function () {
it('should return expected tick, title, and duration', function () {
var expectedDuration = 2;
var test = {
title: expectedTitle,
duration: expectedDuration,
slow: function () {
return 1;
}
};
var runner = createMockRunner(
'pass',
EVENT_TEST_PASS,
null,
null,
test
);
var options = {};
var stdout = runReporter({epilogue: noop}, runner, options);
sinon.restore();
var expectedString =
' ' +
Base.symbols.ok +
' ' +
expectedTitle +
' (' +
expectedDuration +
'ms)' +
' \n';
expect(stdout[0], 'to be', expectedString);
});
});
describe('when test speed is fast', function () {
it('should return expected tick, title without a duration', function () {
var expectedDuration = 1;
var test = {
title: expectedTitle,
duration: expectedDuration,
slow: function () {
return 2;
}
};
var runner = createMockRunner(
'pass',
EVENT_TEST_PASS,
null,
null,
test
);
var options = {};
var stdout = runReporter({epilogue: noop}, runner, options);
sinon.restore();
var expectedString =
' ' + Base.symbols.ok + ' ' + expectedTitle + ' \n';
expect(stdout[0], 'to be', expectedString);
});
});
});
describe("on 'fail' event", function () {
it('should return title and function count', function () {
var functionCount = 1;
var test = {
title: expectedTitle
};
var runner = createMockRunner(
'fail',
EVENT_TEST_FAIL,
null,
null,
test
);
var options = {};
var stdout = runReporter({epilogue: noop}, runner, options);
sinon.restore();
var expectedArray = [
' ' + functionCount + ') ' + expectedTitle + '\n'
];
expect(stdout, 'to equal', expectedArray);
});
});
});
});