Skip to content

Commit

Permalink
Fix flow errors using t.throws and t.notThrows (#1219)
Browse files Browse the repository at this point in the history
Instead of double-defining each of these, define them once while using overloading.

Also took some liberties to improve the definition. Specifically, ava doesn't care what values these throwing functions return, but doesn't produce a return value.

Fixes #1148
  • Loading branch information
leebyron authored and sindresorhus committed Feb 5, 2017
1 parent dcdfbee commit 518252f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions index.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type ErrorValidator =
| ((error: any) => boolean);

/**
* Asertion Types
* Assertion Types
*/

type AssertContext = {
Expand All @@ -57,11 +57,15 @@ type AssertContext = {
notDeepEqual<U>(value: U, expected: U, message?: string): void;
// Assert that function throws an error or promise rejects.
// @param error Can be a constructor, regex, error message or validation function.
throws(value: PromiseLike<mixed>, error?: ErrorValidator, message?: string): Promise<mixed>;
throws(value: () => void, error?: ErrorValidator, message?: string): mixed;
throws: {
(value: PromiseLike<mixed>, error?: ErrorValidator, message?: string): Promise<Error>;
(value: () => mixed, error?: ErrorValidator, message?: string): Error;
};
// Assert that function doesn't throw an error or promise resolves.
notThrows<U>(value: PromiseLike<U>, message?: string): Promise<U>;
notThrows(value: () => void, message?: string): void;
notThrows: {
notThrows<U>(value: PromiseLike<U>, message?: string): Promise<U>;
notThrows(value: () => mixed, message?: string): void;
};
// Assert that contents matches regex.
regex(contents: string, regex: RegExp, message?: string): void;
// Assert that contents does not match regex.
Expand Down

0 comments on commit 518252f

Please sign in to comment.