Skip to content

Instantly share code, notes, and snippets.

@joemaller
Last active November 4, 2015 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joemaller/940bf9c5230cc772c720 to your computer and use it in GitHub Desktop.
Save joemaller/940bf9c5230cc772c720 to your computer and use it in GitHub Desktop.
'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();
})
})
'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();
})
})
'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