Skip to content

Commit

Permalink
Fix lifecycle hook function types (#10480)
Browse files Browse the repository at this point in the history
  • Loading branch information
villasv committed Sep 8, 2020
1 parent bc0eed4 commit ec75280
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,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));

0 comments on commit ec75280

Please sign in to comment.