jest-gwt
Version:
A small library to help Jest support given-when-then style testing without a bunch of overhead
32 lines (26 loc) • 649 B
text/typescript
import type {
beforeEach as jestBeforeEach,
afterEach as jestAfterEach,
} from '@jest/globals';
import { TestContext } from 'gwt-runner';
type Callback<T> = (this: T) => any;
export default (
beforeEach: typeof jestBeforeEach,
afterEach: typeof jestAfterEach,
) => (
<T>(
before: Callback<T>,
after?: Callback<T>,
) => {
beforeEach(async () => {
TestContext.createContext();
await (before.bind(TestContext.context as T) as any)();
});
afterEach(async () => {
if (after) {
await (after.bind(TestContext.context as T) as any)();
}
TestContext.releaseContext();
});
}
);