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 23b9e7b
Show file tree
Hide file tree
Showing 2 changed files with 35 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
41 changes: 34 additions & 7 deletions test/close.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,17 +328,44 @@ 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.test = true
instance.onClose(function (i) {
t.is(arguments.length, 1)
t.ok(i.test)
})
next()
})

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

Expand Down

0 comments on commit 23b9e7b

Please sign in to comment.