This repository has been archived by the owner on Jul 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) | ||
}) |