Skip to content

Commit 76f8349

Browse files
authored
Fix chainable API (#107)
1 parent 681c218 commit 76f8349

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

boot.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function wrap (server, opts, instance) {
3030

3131
server[useKey] = function (fn, opts) {
3232
instance.use(fn, opts)
33-
return instance
33+
return this
3434
}
3535

3636
Object.defineProperty(server, 'then', { get: thenify.bind(instance) })

test/chainable.test.js

+26
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,29 @@ test('chainable automatically binded', (t) => {
6969
t.end()
7070
})
7171
})
72+
73+
test('chainable standalone with server', (t) => {
74+
t.plan(6)
75+
76+
const server = {}
77+
boot(server, {
78+
expose: {
79+
use: 'register'
80+
}
81+
})
82+
83+
const readyResult = server.register(function (ctx, opts, done) {
84+
t.pass('1st plugin')
85+
done()
86+
}).after(function (err, done) {
87+
t.error(err)
88+
t.pass('2nd after')
89+
done()
90+
}).register(function (ctx, opts, done) {
91+
t.pass('3rd plugin')
92+
done()
93+
}).ready(function () {
94+
t.pass('we are ready')
95+
})
96+
t.equal(readyResult, undefined)
97+
})

0 commit comments

Comments
 (0)