Skip to content

Commit 10339bc

Browse files
author
Wolfram Kriesing
committed
+ added config, bugfixes
+ added config tests
1 parent 677576c commit 10339bc

File tree

3 files changed

+106
-2
lines changed

3 files changed

+106
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.kpf

selftest.html

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ <h2>Your result should look like this:</h2>
1616
</pre>
1717

1818
<script type="text/javascript" src="doh.js"></script>
19+
<script type="text/javascript" src="config.js"></script>
1920
<script type="text/javascript" src="util.js"></script>
2021
<script type="text/javascript" src="deferred.js"></script>
2122
<script type="text/javascript" src="assert.js"></script>

selftests.js

+104-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ doh.register("Synchronously written tests.",
8888
]
8989
);
9090

91-
9291
doh.register("Asynchronous tests.",
9392
[
9493
{
@@ -149,6 +148,35 @@ doh.register("Test doh.pause()",
149148
]
150149
);
151150

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+
152180
// When writing a GUI for the tests it happens that you also want to show the
153181
// test cases that succeeded and maybe with what value, that is what the return
154182
// values are for.
@@ -179,8 +207,46 @@ doh.register("Test doh.pause()",
179207
},
180208
]
181209
);
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+
);
182247
})();
183248

249+
184250
// If the test contains asynch parts you can set the "result" property of the test explicitly instead
185251
// of returning a value, like so.
186252
(function(){
@@ -198,7 +264,6 @@ doh.register("Test doh.pause()",
198264
[
199265
testObject,
200266
{
201-
// Still fails :-(
202267
name:"success: Verify result value from last test",
203268
test:function(t){
204269
t.assertEqual(testObject.result, "jaja");
@@ -208,3 +273,40 @@ doh.register("Test doh.pause()",
208273
);
209274
})();
210275

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

Comments
 (0)