Last active
November 4, 2015 14:49
-
-
Save joemaller/940bf9c5230cc772c720 to your computer and use it in GitHub Desktop.
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
'use strict'; | |
var through2 = require('through2'); | |
var should = require('should'); | |
require('mocha'); | |
var failStream = function() { | |
return through2.obj(function(chunk, encoding, callback) { | |
this.push({}) | |
this.emit('error', new Error('failStream has failed')); | |
callback() | |
}) | |
} | |
describe('catch stream errors', function() { | |
it('should throw an error', function(done) { | |
var stream = failStream(); | |
var onerror = function(err) { | |
should.exist(err); | |
err.toString().should.equal('Error: failStream has failed'); | |
this.removeListener('finish', onfinish); | |
done(); | |
}; | |
var onfinish = function() { | |
done(new Error('Expected stream to throw an error.')); | |
}; | |
stream.on('error', onerror) | |
stream.on('finish', onfinish); | |
stream.write(); | |
stream.end(); | |
}) | |
}) |
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
'use strict'; | |
var through2 = require('through2'); | |
var should = require('should'); | |
require('mocha'); | |
var failStream = function() { | |
return through2.obj(function(chunk, encoding, callback) { | |
this.push({}) | |
this.emit('error', new Error('failStream has failed')); | |
callback() | |
}) | |
} | |
describe('catch stream errors', function() { | |
it('should throw an error', function(done) { | |
var stream = failStream(); | |
var errored = false; | |
stream.on('error', function(err) { | |
should.exist(err); | |
errored = true; | |
err.toString().should.equal('Error: failStream has failed'); | |
done(); | |
}) | |
stream.on('finish', function() { | |
if (!errored) { | |
done(new Error('Error suppressed')); | |
} | |
}); | |
stream.write(); | |
stream.end(); | |
}) | |
}) |
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
'use strict'; | |
var through2 = require('through2'); | |
var should = require('should'); | |
require('mocha'); | |
var failStream = function() { | |
return through2.obj(function(chunk, encoding, callback) { | |
this.push({}) | |
this.emit('error', new Error('failStream has failed')); | |
callback() | |
}) | |
} | |
describe('catch stream errors', function() { | |
it('should throw an error', function(done) { | |
var stream = failStream(); | |
stream.on('error', function(err) { | |
should.exist(err); | |
err.toString().should.equal('Error: failStream has failed'); | |
done(); | |
}) | |
stream.on('finish', function() { | |
done(new Error('Why does this still run?')); | |
}); | |
stream.write(); | |
stream.end(); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment