Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
basic muxer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pgte committed Jun 19, 2018
1 parent 9193781 commit 2c0e827
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions test/muxer.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* eslint-env mocha */
'use strict'

const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)

const EventEmitter = require('events')
const pair = require('pull-pair/duplex')

const Muxer = require('../src/muxer')

describe('multiplex-muxer', () => {
let muxer
let multiplex

it('can be created', () => {
const p = pair()
multiplex = new EventEmitter()
muxer = new Muxer(p, multiplex)
})

it('catches newStream errors', (done) => {
multiplex.createStream = () => {
throw new Error('something nbad happened')
}
muxer.newStream((err) => {
expect(err).to.exist()
expect(err.message).to.equal('something nbad happened')
done()
})
})

it('can get destroyed', (done) => {
let destroyed = false
multiplex.destroy = () => {
destroyed = true
setImmediate(() => multiplex.emit('close'))
}

muxer.end((err) => {
expect(err).to.not.exist()
expect(destroyed).to.be.true()
done()
})
})
})

0 comments on commit 2c0e827

Please sign in to comment.