@@ -88,7 +88,6 @@ doh.register("Synchronously written tests.",
88
88
]
89
89
) ;
90
90
91
-
92
91
doh . register ( "Asynchronous tests." ,
93
92
[
94
93
{
@@ -149,6 +148,35 @@ doh.register("Test doh.pause()",
149
148
]
150
149
) ;
151
150
151
+ //
152
+ // Test "config" parameter.
153
+ //
154
+ doh . register ( "Config parameter tests" ,
155
+ [
156
+ {
157
+ name :"success: 'testFunctionName'" ,
158
+ setUp :function ( ) {
159
+ this . _actualTestFunctionName = doh . config . testFunctionName ;
160
+ doh . config . testFunctionName = "myTestFunctionName" ;
161
+ } ,
162
+ myTestFunctionName :function ( t ) {
163
+ t . assertTrue ( true ) ;
164
+ } ,
165
+ tearDown :function ( ) {
166
+ doh . config . testFunctionName = this . _actualTestFunctionName ;
167
+ }
168
+ } ,
169
+ {
170
+ name :"success: reset 'testFunctionName'" ,
171
+ test :function ( t ) {
172
+ t . assertTrue ( true ) ;
173
+ }
174
+ }
175
+ ]
176
+ ) ;
177
+
178
+
179
+
152
180
// When writing a GUI for the tests it happens that you also want to show the
153
181
// test cases that succeeded and maybe with what value, that is what the return
154
182
// values are for.
@@ -179,8 +207,46 @@ doh.register("Test doh.pause()",
179
207
} ,
180
208
]
181
209
) ;
210
+
211
+ // Test a bug that was in the tests, which didn't pass the value returned by a test
212
+ // to the doh.ui.testFinished() function, because that function was called BEFORE
213
+ // the returned value was set into the test data. A pretty tricky asynch
214
+ // problem. The following is the test to verify that it is fixed.
215
+ var resultValue = null ,
216
+ oldTestFinished ;
217
+ doh . register ( "Return value, asynch bug" ,
218
+ [
219
+ {
220
+ name :"success: Verify return value from last test" ,
221
+ setUp :function ( ) {
222
+ // We have to override the testFinished() before we call assert()
223
+ // because with the bug assert() triggered the testFinished()
224
+ // before return was executed.
225
+ oldTestFinished = doh . ui . testFinished ; // Backup the old testFinished().
226
+ doh . ui . testFinished = function ( group , test ) {
227
+ resultValue = test . result ;
228
+ oldTestFinished . apply ( doh . ui , arguments ) ;
229
+ }
230
+ } ,
231
+ test :function ( t ) {
232
+ t . assertTrue ( true ) ;
233
+ return "EXPECT ME" ;
234
+ }
235
+ } ,
236
+ {
237
+ name :"success: Verify result from last test." ,
238
+ setUp :function ( ) {
239
+ doh . ui . testFinished = oldTestFinished ;
240
+ } ,
241
+ test :function ( t ) {
242
+ t . assertEqual ( "EXPECT ME" , resultValue ) ;
243
+ }
244
+ }
245
+ ]
246
+ ) ;
182
247
} ) ( ) ;
183
248
249
+
184
250
// If the test contains asynch parts you can set the "result" property of the test explicitly instead
185
251
// of returning a value, like so.
186
252
( function ( ) {
@@ -198,7 +264,6 @@ doh.register("Test doh.pause()",
198
264
[
199
265
testObject ,
200
266
{
201
- // Still fails :-(
202
267
name :"success: Verify result value from last test" ,
203
268
test :function ( t ) {
204
269
t . assertEqual ( testObject . result , "jaja" ) ;
@@ -208,3 +273,40 @@ doh.register("Test doh.pause()",
208
273
) ;
209
274
} ) ( ) ;
210
275
276
+ /*
277
+ doh.register("Multiple asserts",
278
+ [
279
+ {
280
+ name:"success: some asserts",
281
+ test:function(t){
282
+ t.assertTrue(true);
283
+ t.assertEqual(1, 1);
284
+ t.assertError(new Error());
285
+ }
286
+ },
287
+ {
288
+ name:"fail: last assert fails",
289
+ test:function(t){
290
+ t.assertTrue(true);
291
+ t.assertEqual(1, 1);
292
+ t.assertError(new Error());
293
+
294
+ // FIXXXME multiple asserts dont work yet :(
295
+ t.assertTrue(false);
296
+ }
297
+ },
298
+ {
299
+ name:"fail: last assert fails",
300
+ timeout:12*1000,
301
+ test:function(t){
302
+ t.assertTrue(true);
303
+ setTimeout(function(){
304
+ t.numAsserts++;
305
+ t.assertTrue(false);
306
+ }, 10 * 1000);
307
+ }
308
+ },
309
+ ]
310
+ );
311
+
312
+ //*/
0 commit comments