Skip to content

Commit

Permalink
Avoid evaluating it unless/until itAsync called. (#6719)
Browse files Browse the repository at this point in the history
A safer way to solve #6576 (comment),
given that 4589606 had to be reverted.

This change makes it safe to import the `@apollo/client/testing`
entry point in environments that don't define `global.it`.
  • Loading branch information
benjamn authored Jul 28, 2020
1 parent b718631 commit 891a876
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/utilities/testing/itAsync.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
function wrap<TResult>(
original: (...args: any[]) => TResult,
) {
function wrap<TResult>(key?: "only" | "skip" | "todo") {
return (
message: string,
callback: (
resolve: (result?: any) => void,
reject: (reason?: any) => void,
) => any,
timeout?: number,
) => original(message, function () {
) => (key ? it[key] : it)(message, function () {
return new Promise(
(resolve, reject) => callback.call(this, resolve, reject),
);
}, timeout);
}

const wrappedIt = wrap(it);
const wrappedIt = wrap();
export function itAsync(...args: Parameters<typeof wrappedIt>) {
return wrappedIt.apply(this, args);
}

export namespace itAsync {
export const only = wrap(it.only);
export const skip = wrap(it.skip);
export const todo = wrap(it.todo);
export const only = wrap("only");
export const skip = wrap("skip");
export const todo = wrap("todo");
}

0 comments on commit 891a876

Please sign in to comment.