Skip to content

Commit f17245f

Browse files
committed
add tests for indents and escaping
1 parent 3d154c0 commit f17245f

File tree

1 file changed

+73
-6
lines changed

1 file changed

+73
-6
lines changed

test/reporters/doc.spec.js

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,32 @@ describe('Doc reporter', function () {
1818
describe('on suite', function () {
1919
describe('if suite root does not exist', function () {
2020
var expectedTitle = 'expectedTitle';
21+
var unescapedTitle = '<div>' + expectedTitle + '</div>';
2122
var suite = {
2223
root: false,
2324
title: expectedTitle
2425
};
25-
it('should log html with expected title', function () {
26+
it('should log html with indents and expected title', function () {
27+
runner.on = function (event, callback) {
28+
if (event === 'suite') {
29+
callback(suite);
30+
}
31+
};
32+
Doc.call(this, runner);
33+
process.stdout.write = stdoutWrite;
34+
var expectedArray = [
35+
' <section class="suite">\n',
36+
' <h1>' + expectedTitle + '</h1>\n',
37+
' <dl>\n'
38+
];
39+
stdout.should.deepEqual(expectedArray);
40+
});
41+
it('should escape title where necessary', function () {
42+
var suite = {
43+
root: false,
44+
title: unescapedTitle
45+
};
46+
expectedTitle = '&lt;div&gt;' + expectedTitle + '&lt;/div&gt;';
2647
runner.on = function (event, callback) {
2748
if (event === 'suite') {
2849
callback(suite);
@@ -60,7 +81,7 @@ describe('Doc reporter', function () {
6081
var suite = {
6182
root: false
6283
};
63-
it('should log expected html', function () {
84+
it('should log expected html with indents', function () {
6485
runner.on = function (event, callback) {
6586
if (event === 'suite end') {
6687
callback(suite);
@@ -101,7 +122,7 @@ describe('Doc reporter', function () {
101122
return '';
102123
}
103124
};
104-
it('should log html with expected title and body', function () {
125+
it('should log html with indents and expected title and body', function () {
105126
runner.on = function (event, callback) {
106127
if (event === 'pass') {
107128
callback(test);
@@ -115,30 +136,76 @@ describe('Doc reporter', function () {
115136
];
116137
stdout.should.deepEqual(expectedArray);
117138
});
139+
it('should escape title and body where necessary', function () {
140+
var unescapedTitle = '<div>' + expectedTitle + '</div>';
141+
var unescapedBody = '<div>' + expectedBody + '</div>';
142+
test.title = unescapedTitle;
143+
test.body = unescapedBody;
144+
145+
var expectedEscapedTitle = '&lt;div&gt;' + expectedTitle + '&lt;/div&gt;';
146+
var expectedEscapedBody = '&lt;div&gt;' + expectedBody + '&lt;/div&gt;';
147+
runner.on = function (event, callback) {
148+
if (event === 'pass') {
149+
callback(test);
150+
}
151+
};
152+
Doc.call(this, runner);
153+
process.stdout.write = stdoutWrite;
154+
var expectedArray = [
155+
' <dt>' + expectedEscapedTitle + '</dt>\n',
156+
' <dd><pre><code>' + expectedEscapedBody + '</code></pre></dd>\n'
157+
];
158+
stdout.should.deepEqual(expectedArray);
159+
});
118160
});
119161

120162
describe('on fail', function () {
121163
var expectedTitle = 'some tite';
122164
var expectedBody = 'some body';
165+
var expectedError = 'some error';
123166
var test = {
124167
title: expectedTitle,
125168
body: expectedBody,
126169
slow: function () {
127170
return '';
128171
}
129172
};
130-
it('should log html with expected title and body', function () {
173+
it('should log html with indents and expected title, body and error', function () {
131174
runner.on = function (event, callback) {
132175
if (event === 'fail') {
133-
callback(test);
176+
callback(test, expectedError);
134177
}
135178
};
136179
Doc.call(this, runner);
137180
process.stdout.write = stdoutWrite;
138181
var expectedArray = [
139182
' <dt class="error">' + expectedTitle + '</dt>\n',
140183
' <dd class="error"><pre><code>' + expectedBody + '</code></pre></dd>\n',
141-
' <dd class="error">undefined</dd>\n'
184+
' <dd class="error">' + expectedError + '</dd>\n'
185+
];
186+
stdout.should.deepEqual(expectedArray);
187+
});
188+
it('should escape title, body and error where necessary', function () {
189+
var unescapedTitle = '<div>' + expectedTitle + '</div>';
190+
var unescapedBody = '<div>' + expectedBody + '</div>';
191+
var unescapedError = '<div>' + expectedError + '</div>';
192+
test.title = unescapedTitle;
193+
test.body = unescapedBody;
194+
195+
var expectedEscapedTitle = '&lt;div&gt;' + expectedTitle + '&lt;/div&gt;';
196+
var expectedEscapedBody = '&lt;div&gt;' + expectedBody + '&lt;/div&gt;';
197+
var expectedEscapedError = '&lt;div&gt;' + expectedError + '&lt;/div&gt;';
198+
runner.on = function (event, callback) {
199+
if (event === 'fail') {
200+
callback(test, unescapedError);
201+
}
202+
};
203+
Doc.call(this, runner);
204+
process.stdout.write = stdoutWrite;
205+
var expectedArray = [
206+
' <dt class="error">' + expectedEscapedTitle + '</dt>\n',
207+
' <dd class="error"><pre><code>' + expectedEscapedBody + '</code></pre></dd>\n',
208+
' <dd class="error">' + expectedEscapedError + '</dd>\n'
142209
];
143210
stdout.should.deepEqual(expectedArray);
144211
});

0 commit comments

Comments
 (0)