Skip to content

Commit

Permalink
Propagate error events correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed May 29, 2016
1 parent dc19f1f commit 3e4ca52
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/unexpectedStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ module.exports = {
result = chunks;
}
resolve(result);
});
}, reject);
}).then(function (result) {
return expect.apply(expect, [result, 'to satisfy assertion'].concat(extraArgs));
});
Expand Down
32 changes: 32 additions & 0 deletions test/unexpectedStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,36 @@ describe('unexpected-stream', function () {
}, 'to error', 'ugh');
});
});

describe('with a broken stream that errors', function () {
describe('synchronously', function () {
it('should propagate the error', function () {
var stream = new EventEmitter();
stream.readable = stream.writable = true;
stream.write = function () {
stream.emit('error', new Error('ugh'));
};
stream.end = function () {};
return expect(function () {
return expect(['abc'], 'when piped through', stream, 'to yield output satisfying', 'blabla');
}, 'to error', 'ugh');
});
});

describe('asynchronously', function () {
it('should propagate the error', function () {
var stream = new EventEmitter();
stream.readable = stream.writable = true;
stream.write = function () {
setImmediate(function () {
stream.emit('error', new Error('ugh'));
});
};
stream.end = function () {};
return expect(function () {
return expect(['abc'], 'when piped through', stream, 'to yield output satisfying', 'blabla');
}, 'to error', 'ugh');
});
});
});
});

0 comments on commit 3e4ca52

Please sign in to comment.