Skip to content

Commit 40bac95

Browse files
committed
final touch on tests
1 parent e7b6b86 commit 40bac95

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

test/reporters/base.spec.js

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,15 @@ describe('Base reporter', function () {
135135

136136
describe('diff generation', function () {
137137
var inlineDiffsStub;
138-
var maxDiffSizeStub;
139138

140139
beforeEach(function () {
141-
inlineDiffsStub = sinon.stub(Base, 'inlineDiffs');
142-
maxDiffSizeStub = sinon.stub(Base, 'maxDiffSize');
140+
inlineDiffsStub = sinon.stub(Base, 'inlineDiffs').value(false);
143141
});
144142

145143
it("should generate unified diffs if 'inlineDiffs' is false", function () {
146144
var actual = 'a foo unified diff';
147145
var expected = 'a bar unified diff';
148146

149-
inlineDiffsStub.value(false);
150147
var output = generateDiff(actual, expected);
151148

152149
expect(
@@ -178,7 +175,6 @@ describe('Base reporter', function () {
178175
}
179176
var expected = 'a bar unified diff';
180177

181-
inlineDiffsStub.value(false);
182178
var output = generateDiff(actual, expected);
183179

184180
expect(output, 'to match', /output truncated/);
@@ -192,36 +188,34 @@ describe('Base reporter', function () {
192188
expected += 'a bar unified diff ';
193189
}
194190

195-
inlineDiffsStub.value(false);
196191
var output = generateDiff(actual, expected);
197192

198193
expect(output, 'to match', /output truncated/);
199194
});
200195

201-
it("should not truncate overly long 'actual' if maxDiffSize is zero", function () {
196+
it("should not truncate overly long 'actual' if maxDiffSize=0", function () {
202197
var actual = '';
203198
var i = 0;
204199
while (i++ < 120) {
205200
actual += 'a bar unified diff ';
206201
}
207-
208202
var expected = 'b foo unified diff';
209-
inlineDiffsStub.value(false);
210-
maxDiffSizeStub.value(0);
203+
204+
sinon.stub(Base, 'maxDiffSize').value(0);
211205
var output = generateDiff(actual, expected);
212206

213207
expect(output, 'not to match', /output truncated/);
214208
});
215-
it("should not truncate overly long 'expected' if maxDiffSize is zero", function () {
209+
210+
it("should not truncate overly long 'expected' if maxDiffSize=0", function () {
216211
var actual = 'a foo unified diff';
217212
var expected = '';
218213
var i = 0;
219214
while (i++ < 120) {
220215
expected += 'a bar unified diff ';
221216
}
222217

223-
inlineDiffsStub.value(false);
224-
maxDiffSizeStub.value(0);
218+
sinon.stub(Base, 'maxDiffSize').value(0);
225219
var output = generateDiff(actual, expected);
226220

227221
expect(output, 'not to match', /output truncated/);
@@ -312,6 +306,32 @@ describe('Base reporter', function () {
312306
});
313307
});
314308

309+
describe("when 'reporterOption.maxDiffSize' is provided", function () {
310+
var origSize;
311+
312+
beforeEach(function () {
313+
sinon.restore();
314+
origSize = Base.maxDiffSize;
315+
});
316+
317+
afterEach(function () {
318+
Base.maxDiffSize = origSize;
319+
});
320+
321+
it("should set 'Base.maxDiffSize' used for truncating diffs", function () {
322+
var options = {
323+
reporterOption: {
324+
maxDiffSize: 4
325+
}
326+
};
327+
var suite = new Suite('Dummy suite', 'root');
328+
var runner = new Runner(suite);
329+
// eslint-disable-next-line no-unused-vars
330+
var base = new Base(runner, options);
331+
expect(Base.maxDiffSize, 'to be', 4);
332+
});
333+
});
334+
315335
it('should stringify objects', function () {
316336
var err = new Error('test');
317337
err.actual = {key: 'a1'};
@@ -491,6 +511,7 @@ describe('Base reporter', function () {
491511
var baseConsoleLog;
492512

493513
beforeEach(function () {
514+
sinon.restore();
494515
sinon.stub(console, 'log');
495516
baseConsoleLog = sinon.stub(Base, 'consoleLog');
496517
});
@@ -502,24 +523,5 @@ describe('Base reporter', function () {
502523
expect(baseConsoleLog, 'was called');
503524
expect(console.log, 'was not called');
504525
});
505-
506-
afterEach(function () {
507-
sinon.restore();
508-
});
509-
});
510-
});
511-
describe('when "reporterOption.maxDiffSize" is provided', function () {
512-
it('should be the effective value used for tuncating diffs', function () {
513-
var options = {
514-
reporterOption: {
515-
maxDiffSize: 4
516-
}
517-
};
518-
var mocha = new Mocha();
519-
var suite = new Suite('Dummy suite', 'root');
520-
var runner = new Runner(suite);
521-
// eslint-disable-next-line no-unused-vars
522-
var mochaReporter = new mocha._reporter(runner, options);
523-
expect(Base.maxDiffSize, 'to be', 4);
524526
});
525527
});

0 commit comments

Comments
 (0)