Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cemremengu committed Sep 10, 2018
1 parent c1b841f commit cd48ac9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ function encapsulateTwoParam (func, that) {
func()
process.nextTick(cb)
} else if (func.length === 1) {
func(cb)
func(this)
process.nextTick(cb)
} else {
func(this, cb)
Expand Down
40 changes: 33 additions & 7 deletions test/close.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,17 +328,43 @@ test('close without a cb', (t) => {
app.close()
})

test('close without an instance', (t) => {
t.plan(2)
test('onClose with 0 parameters', (t) => {
t.plan(4)

const app = boot()
const server = { my: 'server' }
const app = boot(server)

app.onClose((done) => {
t.ok('called')
app.use(function (instance, opts, next) {
instance.onClose(function () {
t.ok('called')
t.is(arguments.length, 0)
})
next()
})

app.close(() => {
t.pass('closed')
app.close(err => {
t.error(err)
t.pass('Closed')
})
})

test('onClose with 1 parameter', (t) => {
t.plan(4)

const server = { my: 'server' }
const app = boot(server)

app.use(function (instance, opts, next) {
instance.onClose(function (done) {
t.ok('called')
t.is(arguments.length, 1)
})
next()
})

app.close(err => {
t.error(err)
t.pass('Closed')
})
})

Expand Down

0 comments on commit cd48ac9

Please sign in to comment.