forked from bentomas/node-async-testing
/
test-readme.js
55 lines (50 loc) · 1.37 KB
/
test-readme.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var TestSuite = require('../async_testing').TestSuite;
exports['README examples suite'] = (new TestSuite())
.setup(function(callback) {
this.foo = 'bar';
process.nextTick(function() {
callback();
});
})
.teardown(function(callback) {
this.foo = null;
process.nextTick(function() {
callback();
});
})
.addTests({
"simple asynchronous": function(assert, finished) {
setTimeout(function() {
assert.ok(true);
finished();
},50);
},
"simple synchronous": function(assert) {
assert.ok(true);
},
"synchronous foo equal bar": function(assert) {
assert.equal('bar', this.foo);
},
"asynchronous foo equal bar": function(assert, finished, test) {
process.nextTick(function() {
assert.equal('bar', test.foo);
finished();
});
},
"assertions expected (fails)": function(assert) {
this.numAssertionsExpected = 3;
assert.ok(true);
// this test will fail!
},
"uncaughtException listener": function(assert, finished, test) {
test.numAssertionsExpected = 1;
test.addListener('uncaughtException', function(err) {
assert.equal('hello', err.message);
finished();
});
throw new Error('hello');
}
});
if (module === require.main) {
require('../async_testing').runSuites(exports);
}