feat: conditionally emit errors

test: add tests for emit override
This commit is contained in:
Jacob Heun
2018-11-12 15:43:32 +01:00
parent e92053da9a
commit f71fdfdf35
2 changed files with 39 additions and 0 deletions

View File

@ -80,4 +80,25 @@ describe('libp2p creation', () => {
done()
})
})
it('should not throw errors from switch if node has no error listeners', (done) => {
createNode([], {}, (err, node) => {
expect(err).to.not.exist()
node._switch.emit('error', new Error('bad things'))
done()
})
})
it('should emit errors from switch if node has error listeners', (done) => {
const error = new Error('bad things')
createNode([], {}, (err, node) => {
expect(err).to.not.exist()
node.once('error', (err) => {
expect(err).to.eql(error)
done()
})
node._switch.emit('error', error)
})
})
})