fix: start and stop error callback (#316)

* fix: ensure start and stop callbacks are called
This commit is contained in:
Jacob Heun
2019-02-01 16:32:34 +01:00
committed by GitHub
parent c4cab007af
commit 8047fb76fa
4 changed files with 62 additions and 6 deletions

View File

@ -26,6 +26,7 @@ describe('libp2p state machine (fsm)', () => {
})
afterEach(() => {
node.removeAllListeners()
sinon.restore()
})
after((done) => {
node.stop(done)
@ -64,6 +65,23 @@ describe('libp2p state machine (fsm)', () => {
node.start()
})
it('should callback with an error when it occurs on stop', (done) => {
const error = new Error('some error starting')
node.once('start', () => {
node.once('error', (err) => {
expect(err).to.eql(error).mark()
})
node.stop((err) => {
expect(err).to.eql(error).mark()
})
})
expect(2).checks(done)
sinon.stub(node._switch, 'stop').callsArgWith(0, error)
node.start()
})
it('should noop when starting a started node', (done) => {
node.once('start', () => {
node.state.on('STARTING', () => {
@ -116,9 +134,11 @@ describe('libp2p state machine (fsm)', () => {
throw new Error('should not start')
})
expect(2).checks(done)
expect(3).checks(done)
node.start()
node.start((err) => {
expect(err).to.eql(error).mark()
})
})
it('should not dial when the node is stopped', (done) => {