Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use RegExp for test.throws() #183

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions reference-implementation/test/count-queuing-strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ test('Number-ish high water marks get converted to numbers', t => {

test('Gives a RangeError when the number is negative', t => {
t.throws(() => new CountQueuingStrategy({ highWaterMark: -4 }),
RangeError,
/RangeError/,
'throws for { highWaterMark: -4 }');

t.throws(() => new CountQueuingStrategy({ highWaterMark: '-4' }),
RangeError,
/RangeError/,
'throws for { highWaterMark: \'-4\' }');

t.end();
Expand Down
16 changes: 9 additions & 7 deletions reference-implementation/test/readable-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ test('ReadableStream reading a closed stream throws a TypeError', t => {
}
});

t.throws(() => rs.read(), TypeError);
t.throws(() => rs.read(), /TypeError/);
});

test(`ReadableStream reading a stream makes wait() and closed return a promise resolved with undefined when the stream
Expand All @@ -78,7 +78,7 @@ test(`ReadableStream reading a stream makes wait() and closed return a promise r
t.equal(rs.read(), 'test', 'A test string should be read');
t.equal(rs.state, 'closed', 'The stream should be in closed state');

t.throws(() => rs.read(), TypeError);
t.throws(() => rs.read(), /TypeError/);

rs.wait().then(
v => t.equal(v, undefined, 'wait() should return a promise resolved with undefined'),
Expand Down Expand Up @@ -119,10 +119,12 @@ test('ReadableStream start throws an error', t => {

var error = new Error('aaaugh!!');

t.throws(
() => new ReadableStream({ start() { throw error; } }),
caught => t.equal(caught, error, 'error was allowed to propagate')
);
try {
new ReadableStream({ start() { throw error; } });
t.fail('Constructor didn\'t throw');
} catch (caughtError) {
t.strictEqual(caughtError, error, 'error was allowed to propagate');
}
});

test('ReadableStream pull throws an error', t => {
Expand Down Expand Up @@ -368,7 +370,7 @@ test('ReadableStream enqueue fails when the stream is in closing state', t => {

t.throws(
() => t.equal(enqueue('b'), false),
TypeError,
/TypeError/,
'enqueue after close must throw a TypeError'
);
},
Expand Down
14 changes: 12 additions & 2 deletions reference-implementation/test/transform-stream-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ test('TransformStream errors thrown in transform put the input and output in an
t.equal(ts.output.state, 'errored', 'output becomes errored after writing to the throwing transform');
t.equal(ts.input.state, 'errored', 'input becomes errored after writing to the throwing transform');

t.throws(() => ts.output.read(), thrownError, 'output\'s read should throw the thrown error');
try {
ts.output.read();
t.fail('read() didn\'nt throw');
} catch (error) {
t.strictEqual(error, thrownError, 'output\'s read should throw the thrown error');
}
}, 0);

ts.output.wait().then(
Expand Down Expand Up @@ -73,7 +78,12 @@ test('TransformStream errors thrown in flush put the input and output in an erro
t.equal(ts.output.state, 'errored', 'output becomes errored after closing with the throwing flush');
t.equal(ts.input.state, 'errored', 'input becomes errored after closing with the throwing flush');

t.throws(() => ts.output.read(), thrownError, 'output\'s read should throw the thrown error');
try {
ts.output.read();
t.fail('read() didn\'nt throw');
} catch (error) {
t.strictEqual(error, thrownError, 'output\'s read should throw the thrown error');
}
}, 0);

ts.output.wait().then(
Expand Down
4 changes: 2 additions & 2 deletions reference-implementation/test/transform-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ test('TransformStream can be constructed with a transform function', t => {

test('TransformStream cannot be constructed with no transform function', t => {
t.plan(2);
t.throws(() => new TransformStream(), TypeError, 'TransformStream cannot be constructed with no arguments');
t.throws(() => new TransformStream({ }), TypeError, 'TransformStream cannot be constructed with an empty object');
t.throws(() => new TransformStream(), /TypeError/, 'TransformStream cannot be constructed with no arguments');
t.throws(() => new TransformStream({ }), /TypeError/, 'TransformStream cannot be constructed with an empty object');
});

test('TransformStream instances must have input and output properties of the correct types', t => {
Expand Down