Skip to content

Commit

Permalink
add tests for indents and escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
craigtaub committed Jan 28, 2017
1 parent 3d154c0 commit f17245f
Showing 1 changed file with 73 additions and 6 deletions.
79 changes: 73 additions & 6 deletions test/reporters/doc.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,32 @@ describe('Doc reporter', function () {
describe('on suite', function () {
describe('if suite root does not exist', function () {
var expectedTitle = 'expectedTitle';
var unescapedTitle = '<div>' + expectedTitle + '</div>';
var suite = {
root: false,
title: expectedTitle
};
it('should log html with expected title', function () {
it('should log html with indents and expected title', function () {
runner.on = function (event, callback) {
if (event === 'suite') {
callback(suite);
}
};
Doc.call(this, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
' <section class="suite">\n',
' <h1>' + expectedTitle + '</h1>\n',
' <dl>\n'
];
stdout.should.deepEqual(expectedArray);
});
it('should escape title where necessary', function () {
var suite = {
root: false,
title: unescapedTitle
};
expectedTitle = '&lt;div&gt;' + expectedTitle + '&lt;/div&gt;';
runner.on = function (event, callback) {
if (event === 'suite') {
callback(suite);
Expand Down Expand Up @@ -60,7 +81,7 @@ describe('Doc reporter', function () {
var suite = {
root: false
};
it('should log expected html', function () {
it('should log expected html with indents', function () {
runner.on = function (event, callback) {
if (event === 'suite end') {
callback(suite);
Expand Down Expand Up @@ -101,7 +122,7 @@ describe('Doc reporter', function () {
return '';
}
};
it('should log html with expected title and body', function () {
it('should log html with indents and expected title and body', function () {
runner.on = function (event, callback) {
if (event === 'pass') {
callback(test);
Expand All @@ -115,30 +136,76 @@ describe('Doc reporter', function () {
];
stdout.should.deepEqual(expectedArray);
});
it('should escape title and body where necessary', function () {
var unescapedTitle = '<div>' + expectedTitle + '</div>';
var unescapedBody = '<div>' + expectedBody + '</div>';
test.title = unescapedTitle;
test.body = unescapedBody;

var expectedEscapedTitle = '&lt;div&gt;' + expectedTitle + '&lt;/div&gt;';
var expectedEscapedBody = '&lt;div&gt;' + expectedBody + '&lt;/div&gt;';
runner.on = function (event, callback) {
if (event === 'pass') {
callback(test);
}
};
Doc.call(this, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
' <dt>' + expectedEscapedTitle + '</dt>\n',
' <dd><pre><code>' + expectedEscapedBody + '</code></pre></dd>\n'
];
stdout.should.deepEqual(expectedArray);
});
});

describe('on fail', function () {
var expectedTitle = 'some tite';
var expectedBody = 'some body';
var expectedError = 'some error';
var test = {
title: expectedTitle,
body: expectedBody,
slow: function () {
return '';
}
};
it('should log html with expected title and body', function () {
it('should log html with indents and expected title, body and error', function () {
runner.on = function (event, callback) {
if (event === 'fail') {
callback(test);
callback(test, expectedError);
}
};
Doc.call(this, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
' <dt class="error">' + expectedTitle + '</dt>\n',
' <dd class="error"><pre><code>' + expectedBody + '</code></pre></dd>\n',
' <dd class="error">undefined</dd>\n'
' <dd class="error">' + expectedError + '</dd>\n'
];
stdout.should.deepEqual(expectedArray);
});
it('should escape title, body and error where necessary', function () {
var unescapedTitle = '<div>' + expectedTitle + '</div>';
var unescapedBody = '<div>' + expectedBody + '</div>';
var unescapedError = '<div>' + expectedError + '</div>';
test.title = unescapedTitle;
test.body = unescapedBody;

var expectedEscapedTitle = '&lt;div&gt;' + expectedTitle + '&lt;/div&gt;';
var expectedEscapedBody = '&lt;div&gt;' + expectedBody + '&lt;/div&gt;';
var expectedEscapedError = '&lt;div&gt;' + expectedError + '&lt;/div&gt;';
runner.on = function (event, callback) {
if (event === 'fail') {
callback(test, unescapedError);
}
};
Doc.call(this, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
' <dt class="error">' + expectedEscapedTitle + '</dt>\n',
' <dd class="error"><pre><code>' + expectedEscapedBody + '</code></pre></dd>\n',
' <dd class="error">' + expectedEscapedError + '</dd>\n'
];
stdout.should.deepEqual(expectedArray);
});
Expand Down

0 comments on commit f17245f

Please sign in to comment.