@@ -18,11 +18,32 @@ describe('Doc reporter', function () {
18
18
describe ( 'on suite' , function ( ) {
19
19
describe ( 'if suite root does not exist' , function ( ) {
20
20
var expectedTitle = 'expectedTitle' ;
21
+ var unescapedTitle = '<div>' + expectedTitle + '</div>' ;
21
22
var suite = {
22
23
root : false ,
23
24
title : expectedTitle
24
25
} ;
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 = '<div>' + expectedTitle + '</div>' ;
26
47
runner . on = function ( event , callback ) {
27
48
if ( event === 'suite' ) {
28
49
callback ( suite ) ;
@@ -60,7 +81,7 @@ describe('Doc reporter', function () {
60
81
var suite = {
61
82
root : false
62
83
} ;
63
- it ( 'should log expected html' , function ( ) {
84
+ it ( 'should log expected html with indents ' , function ( ) {
64
85
runner . on = function ( event , callback ) {
65
86
if ( event === 'suite end' ) {
66
87
callback ( suite ) ;
@@ -101,7 +122,7 @@ describe('Doc reporter', function () {
101
122
return '' ;
102
123
}
103
124
} ;
104
- it ( 'should log html with expected title and body' , function ( ) {
125
+ it ( 'should log html with indents and expected title and body' , function ( ) {
105
126
runner . on = function ( event , callback ) {
106
127
if ( event === 'pass' ) {
107
128
callback ( test ) ;
@@ -115,30 +136,76 @@ describe('Doc reporter', function () {
115
136
] ;
116
137
stdout . should . deepEqual ( expectedArray ) ;
117
138
} ) ;
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 = '<div>' + expectedTitle + '</div>' ;
146
+ var expectedEscapedBody = '<div>' + expectedBody + '</div>' ;
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
+ } ) ;
118
160
} ) ;
119
161
120
162
describe ( 'on fail' , function ( ) {
121
163
var expectedTitle = 'some tite' ;
122
164
var expectedBody = 'some body' ;
165
+ var expectedError = 'some error' ;
123
166
var test = {
124
167
title : expectedTitle ,
125
168
body : expectedBody ,
126
169
slow : function ( ) {
127
170
return '' ;
128
171
}
129
172
} ;
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 ( ) {
131
174
runner . on = function ( event , callback ) {
132
175
if ( event === 'fail' ) {
133
- callback ( test ) ;
176
+ callback ( test , expectedError ) ;
134
177
}
135
178
} ;
136
179
Doc . call ( this , runner ) ;
137
180
process . stdout . write = stdoutWrite ;
138
181
var expectedArray = [
139
182
' <dt class="error">' + expectedTitle + '</dt>\n' ,
140
183
' <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 = '<div>' + expectedTitle + '</div>' ;
196
+ var expectedEscapedBody = '<div>' + expectedBody + '</div>' ;
197
+ var expectedEscapedError = '<div>' + expectedError + '</div>' ;
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'
142
209
] ;
143
210
stdout . should . deepEqual ( expectedArray ) ;
144
211
} ) ;
0 commit comments