Skip to content

Commit

Permalink
types(vest): fix promisify types (#563)
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Jan 21, 2021
1 parent 20a047b commit d566a32
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
6 changes: 6 additions & 0 deletions packages/vest/src/__tests__/test_types/fixtures/suite.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import promisify from 'vest/promisify';

import vest from 'vest';

vest.create('suite_name', () => {});
Expand Down Expand Up @@ -91,3 +93,7 @@ getResult.tests.someField.warnCount;
getResult.tests.someField.testCount;
getResult.tests.someField.errors[0];
getResult.tests.someField.warnings[0];

const promisified = promisify(v);

promisified({}).then(() => {});
2 changes: 1 addition & 1 deletion packages/vest/src/typings/promisify.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { IVestResult, DraftResult } from './vestResult';

declare function promisify(
validatorFn: (...args: any[]) => IVestResult
): Promise<DraftResult>;
): (...args: any[]) => Promise<DraftResult>;

export default promisify;
15 changes: 9 additions & 6 deletions packages/vest/src/typings/vestResult.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type DoneCB = (res: DraftResult) => void;

export type IVestResult = {
export type DraftResult = {
name: string;
errorCount: number;
warnCount: number;
Expand Down Expand Up @@ -83,14 +83,17 @@ export type IVestResult = {
* Returns all the warning messages for the specified group and field
*/
getWarningsByGroup(groupName: string, fieldName: string): string[];
};

type DoneResult = {
/**
* Runs a callback when all tests are finished running
* Runs a callback when all tests of the specified field finished running
*/
done(cb: DoneCB): void;
done(fieldName: string, cb: DoneCB): IVestResult;
/**
* Runs a callback when all tests of the specified field finished running
* Runs a callback when all tests are finished running
*/
done(fieldName: string, cb: DoneCB): void;
done(cb: DoneCB): IVestResult;
};

export type DraftResult = Omit<IVestResult, 'done'>;
export interface IVestResult extends DoneResult, DraftResult {}

0 comments on commit d566a32

Please sign in to comment.