forked from kolodny/exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
68 lines (51 loc) · 1.25 KB
/
test.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
56
57
58
59
60
61
62
63
64
65
66
67
68
var assert = require('assert');
var Middleware = require('./');
describe('middleware', function() {
it('works with a single instance', function(done) {
var middleware = new Middleware();
middleware.use(function(next) {
var ctx = this;
setTimeout(function() {
ctx.first = true;
next();
}, 10);
});
middleware.use(function(next) {
var ctx = this;
setTimeout(function() {
ctx.second = true;
next();
}, 10);
});
middleware.go(function() {
assert.equal(this.first, true);
assert.equal(this.second, true);
done();
});
});
it('works with multiple instances', function(done) {
var middleware1 = new Middleware();
var middleware2 = new Middleware();
middleware1.use(function(next) {
var ctx = this;
setTimeout(function() {
ctx.first = true;
next();
}, 10);
});
middleware2.use(function(next) {
var ctx = this;
setTimeout(function() {
ctx.second = true;
next();
}, 10);
});
middleware1.go(function() {
assert.equal(this.first, true);
middleware2.go(function() {
assert.equal(this.second, true);
done();
})
});
});
});