Skip to content

Commit

Permalink
catch all branches by adding window width tests
Browse files Browse the repository at this point in the history
  • Loading branch information
craigtaub committed Jan 29, 2017
1 parent 5cd7c3e commit 763698c
Showing 1 changed file with 121 additions and 47 deletions.
168 changes: 121 additions & 47 deletions test/reporters/dot.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('Dot reporter', function () {
var stdoutWrite;
var runner;
var useColors;
var windowWidth;

beforeEach(function () {
stdout = [];
Expand All @@ -18,11 +19,14 @@ describe('Dot reporter', function () {
stdout.push(string);
};
useColors = Base.useColors;
windowWidth = Base.window.width;
Base.useColors = false;
Base.window.width = 0;
});

afterEach(function () {
Base.useColors = useColors;
Base.window.width = windowWidth;
});

describe('on start', function () {
Expand All @@ -41,84 +45,154 @@ describe('Dot reporter', function () {
});
});
describe('on pending', function () {
it('should return a new line and a coma', function () {
runner.on = function (event, callback) {
if (event === 'pending') {
callback();
}
};
Dot.call({epilogue: function () {}}, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
'\n ',
Base.symbols.comma
];
stdout.should.deepEqual(expectedArray);
describe('if window width is greater than 1', function () {
beforeEach(function () {
Base.window.width = 2;
});
it('should return a new line and then a coma', function () {
runner.on = function (event, callback) {
if (event === 'pending') {
callback();
}
};
Dot.call({epilogue: function () {}}, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
'\n ',
Base.symbols.comma
];
stdout.should.deepEqual(expectedArray);
});
});
describe('if window width is equal to or less than 1', function () {
it('should return a coma', function () {
runner.on = function (event, callback) {
if (event === 'pending') {
callback();
}
};
Dot.call({epilogue: function () {}}, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
Base.symbols.comma
];
stdout.should.deepEqual(expectedArray);
});
});
});
describe('on pass', function () {
describe('if test speed is fast', function () {
it('should return a new line and a dot', function () {
describe('if window width is greater than 1', function () {
beforeEach(function () {
Base.window.width = 2;
});
describe('if test speed is fast', function () {
it('should return a new line and then a dot', function () {
var test = {
duration: 1,
slow: function () { return 2; }
};
runner.on = function (event, callback) {
if (event === 'pass') {
callback(test);
}
};
Dot.call({epilogue: function () {}}, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
'\n ',
Base.symbols.dot
];
stdout.should.deepEqual(expectedArray);
});
});
});
describe('if window width is equal to or less than 1', function () {
describe('if test speed is fast', function () {
it('should return a dot', function () {
var test = {
duration: 1,
slow: function () { return 2; }
};
runner.on = function (event, callback) {
if (event === 'pass') {
callback(test);
}
};
Dot.call({epilogue: function () {}}, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
Base.symbols.dot
];
stdout.should.deepEqual(expectedArray);
});
});
describe('if test speed is slow', function () {
it('should return a dot', function () {
var test = {
duration: 2,
slow: function () { return 1; }
};
runner.on = function (event, callback) {
if (event === 'pass') {
callback(test);
}
};
Dot.call({epilogue: function () {}}, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
Base.symbols.dot
];
stdout.should.deepEqual(expectedArray);
});
});
});
});
describe('on fail', function () {
describe('if window width is greater than 1', function () {
beforeEach(function () {
Base.window.width = 2;
});
it('should return a new line and then an exclamation mark', function () {
var test = {
duration: 1,
slow: function () { return 2; }
test: {
err: 'some error'
}
};
runner.on = function (event, callback) {
if (event === 'pass') {
if (event === 'fail') {
callback(test);
}
};
Dot.call({epilogue: function () {}}, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
'\n ',
Base.symbols.dot
Base.symbols.bang
];
stdout.should.deepEqual(expectedArray);
});
});
describe('if test speed is slow', function () {
it('should return a new line and a dot', function () {
describe('if window width is equal to or less than 1', function () {
it('should return an exclamation mark', function () {
var test = {
duration: 2,
slow: function () { return 1; }
test: {
err: 'some error'
}
};
runner.on = function (event, callback) {
if (event === 'pass') {
if (event === 'fail') {
callback(test);
}
};
Dot.call({epilogue: function () {}}, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
'\n ',
Base.symbols.dot
Base.symbols.bang
];
stdout.should.deepEqual(expectedArray);
});
});
});
describe('on fail', function () {
it('should return a new line and a exclamation mark', function () {
var test = {
test: {
err: 'some error'
}
};
runner.on = function (event, callback) {
if (event === 'fail') {
callback(test);
}
};
Dot.call({epilogue: function () {}}, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
'\n ',
Base.symbols.bang
];
stdout.should.deepEqual(expectedArray);
});
});
describe('on end', function () {
it('should call the epilogue', function () {
runner.on = function (event, callback) {
Expand Down

0 comments on commit 763698c

Please sign in to comment.