Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lifecycle hook function types #10480

Merged
merged 1 commit into from Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,8 @@

### Fixes

- Fix lifecycle hook function types ([#10480](https://github.com/facebook/jest/pull/10480))

### Chore & Maintenance

### Performance
Expand Down
12 changes: 8 additions & 4 deletions packages/jest-types/src/Global.ts
Expand Up @@ -47,6 +47,10 @@ type Each<EachCallback extends TestCallback> =
) => void)
| (() => void);

export interface HookBase {
(fn: HookFn, timeout?: number): void;
}

export interface ItBase {
(testName: TestName, fn: TestFn, timeout?: number): void;
each: Each<TestFn>;
Expand Down Expand Up @@ -91,10 +95,10 @@ export interface TestFrameworkGlobals {
describe: Describe;
xdescribe: DescribeBase;
fdescribe: DescribeBase;
beforeAll: HookFn;
beforeEach: HookFn;
afterEach: HookFn;
afterAll: HookFn;
beforeAll: HookBase;
beforeEach: HookBase;
afterEach: HookBase;
afterAll: HookBase;
}

export interface GlobalAdditions extends TestFrameworkGlobals {
Expand Down
25 changes: 25 additions & 0 deletions test-types/top-level-globals.test.ts
@@ -0,0 +1,25 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @type ./empty.d.ts
*/

import {expectType} from 'mlh-tsd';
//eslint-disable-next-line import/no-extraneous-dependencies
import {afterAll, afterEach, beforeAll, beforeEach} from '@jest/globals';

const fn = () => {};
const timeout = 5;

// https://jestjs.io/docs/en/api#methods
expectType<void>(afterAll(fn));
expectType<void>(afterAll(fn, timeout));
expectType<void>(afterEach(fn));
expectType<void>(afterEach(fn, timeout));
expectType<void>(beforeAll(fn));
expectType<void>(beforeAll(fn, timeout));
expectType<void>(beforeEach(fn));
expectType<void>(beforeEach(fn, timeout));