-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Better TypeScript typing for throws assertions #1956
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
Changes from all commits
f78636e
ec35588
033b961
032ea1b
95cc5fa
dd38b3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// @flow | ||
import test from '../../index.js.flow'; | ||
|
||
class CustomError extends Error { | ||
foo: string; | ||
|
||
constructor() { | ||
super(); | ||
this.foo = 'foo'; | ||
} | ||
} | ||
|
||
test('throws', t => { | ||
const err1: Error = t.throws(() => {}); | ||
// t.is(err1.foo, 'foo'); | ||
const err2: CustomError = t.throws(() => {}); | ||
t.is(err2.foo, 'foo'); | ||
const err3 = t.throws<CustomError>(() => {}); | ||
t.is(err3.foo, 'foo'); | ||
}); | ||
|
||
test('throwsAsync', async t => { | ||
const err1: Error = await t.throwsAsync(Promise.reject()); | ||
// t.is(err1.foo, 'foo'); | ||
const err2 = await t.throwsAsync<CustomError>(Promise.reject()); | ||
t.is(err2.foo, 'foo'); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import test from '../..'; | ||
|
||
class CustomError extends Error { | ||
foo: string; | ||
|
||
constructor() { | ||
super(); | ||
this.foo = 'foo'; | ||
} | ||
} | ||
|
||
test('throws', t => { | ||
const err1: Error = t.throws(() => {}); | ||
// t.is(err1.foo, 'foo'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a type exception. I think maybe there's a way to indicate that to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use the |
||
const err2: CustomError = t.throws(() => {}); | ||
t.is(err2.foo, 'foo'); | ||
const err3 = t.throws<CustomError>(() => {}); | ||
t.is(err3.foo, 'foo'); | ||
}); | ||
|
||
test('throwsAsync', async t => { | ||
const err1: Error = await t.throwsAsync(Promise.reject()); | ||
// t.is(err1.foo, 'foo'); | ||
const err2 = await t.throwsAsync<CustomError>(Promise.reject()); | ||
t.is(err2.foo, 'foo'); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also include the contents of
myFunc
somewhere as it's not that clear whereTypeError
comes from.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.