-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Description
Description
The flow type for AssetContext.throws specifies that the return value is Promise<Error>:
type AssertContext = {
...
throws: {
(value: PromiseLike<mixed>, error?: ErrorValidator, message?: string): Promise<Error>;
(value: () => mixed, error?: ErrorValidator, message?: string): Error;
};
...
};
This is inconsistent with the typescript types:
export interface AssertContext {
...
throws(value: PromiseLike<any>, error?: ErrorValidator, message?: string): Promise<any>;
throws(value: () => void, error?: ErrorValidator, message?: string): any;
...
}
and causes issues with flow when your code throws something other than an Error object.
Test Source
//@flow
import test from 'ava';
class CustomError extends Error {
customProperty: string;
constructor(message: string, customValue: string) {
super(message);
this.customProperty = customValue;
}
}
function throwsCustomError(): Promise<string> {
return new Promise((resolve, reject) => {
setTimeout(() => {
reject(new CustomError('message', 'customValue'));
}, 500);
});
}
test('Test something', async (tt: AssertContext): Promise<void> => {
const error = await tt.throws(throwsCustomError());
tt.is(error.customProperty, 'customValue');
});Error Message & Stack Trace
test.js:22
22: tt.is(error.customProperty, 'customValue');
^^^^^^^^^^^^^^ property `customProperty`. Property not found in
22: tt.is(error.customProperty, 'customValue');
^^^^^ Error
Found 1 error
error Command failed with exit code 2.
Config
Copy the relevant section from package.json:
{
"ava": {
"babel": "inherit"
}
}Relevant Links
I'll submit a PR in a min with a fix
Metadata
Metadata
Assignees
Labels
No labels