Skip to content

Commit

Permalink
Fix flow errors using t.throws and t.notThrows
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 avajs#1148
  • Loading branch information
leebyron committed Feb 2, 2017
1 parent 2623c11 commit 164e092
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 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,17 @@ 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<void>;
(value: () => mixed, error?: ErrorValidator, message?: string): void;
};
// throws(value: PromiseLike<mixed>, error?: ErrorValidator, message?: string): Promise<mixed>;
// throws(value: () => void, error?: ErrorValidator, message?: string): mixed;
// 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 164e092

Please sign in to comment.