Skip to content

Commit

Permalink
add tests of unreferencing
Browse files Browse the repository at this point in the history
  • Loading branch information
schwarzkopfb committed Aug 9, 2016
1 parent c774052 commit 40d000b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
20 changes: 10 additions & 10 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ test.doesNotThrow(
test.type(n.transform, 'function', '`transform` should have a default fn')

test.test('chaining', function (test) {
test.plan(4)
test.plan(5)

n.save = function (userId, channel, target, callback) {
callback()
Expand All @@ -77,12 +77,13 @@ test.test('chaining', function (test) {
test.equal(n.send(1, 'foo', noop), n, '`send()` should be chainable')
test.equal(n.register(1, 'foo', 'bar', noop), n, '`register()` should be chainable')
test.equal(n.unregister(1, 'foo', noop), n, '`unregister()` should be chainable')
test.equal(n.unref(), n, '`unref()` should be chainable')

test.end()
})

test.test('plugin', function (test) {
test.plan(4)
test.plan(5)

var p = new Plugin

Expand All @@ -100,14 +101,13 @@ test.test('plugin', function (test) {
assert.AssertionError,
'plugin `send` fn exposition should be enforced'
)
// todo: WTF it breaks `tap` (again)
// test.throws(
// function () {
// p.destroy
// },
// assert.AssertionError,
// 'plugin `destroy` fn exposition should be enforced'
// )
test.throws(
function () {
p.destroy
},
assert.AssertionError,
'plugin `destroy` fn exposition should be enforced'
)

// set the name otherwise it still throws ans
// inspect will try to get that
Expand Down
28 changes: 24 additions & 4 deletions test/plugins.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
'use strict'

var assert = require('assert'),
inherits = require('util').inherits,
test = require('tap'),
Handover = require('../'),
n = new Handover,
p1 = require('./plugin1'),
opts = { test: 42 },
p1inst = new p1(opts)

test.plan(2)
test.plan(3)

function noop() {
}
Expand Down Expand Up @@ -90,8 +91,6 @@ test.test('`use()` signatures', function (test) {
assert.AssertionError,
'`use()` should assert its args'
)

test.end()
})

test.test('error delegation', function (test) {
Expand All @@ -109,6 +108,27 @@ test.test('error delegation', function (test) {
test.equal(err, 'test', 'non-standard error values should not cause any problem')
})
p1inst.emitError('test')
})

test.test('unref', function (test) {
test.plan(2)

function TestPlugin() {
Handover.Plugin.call(this)
this.name = 'test'
this.send = function (a, b, c) {}
this.unref = function () {
test.pass('`unref()` called instead of destroy')
}
this.destroy = function () {
test.pass('`destroy()` is used when no `unref()` present')
}
}
inherits(TestPlugin, Handover.Plugin)
var plugin = new TestPlugin

test.end()
n.use(plugin)
n.unref()
delete plugin.unref
n.unref()
})

0 comments on commit 40d000b

Please sign in to comment.