-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement tests for type definitions in Jest (#10407)
Co-authored-by: Karan Sanjeev <[email protected]>
- Loading branch information
1 parent
c9c8dba
commit 200adc0
Showing
8 changed files
with
612 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,8 @@ jobs: | |
run: yarn | ||
- name: build | ||
run: yarn build | ||
- name: test typings | ||
run: yarn test-types | ||
- name: verify [email protected] compatibility | ||
run: yarn verify-old-ts | ||
- name: run eslint | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const baseConfig = require('./jest.config'); | ||
|
||
const { | ||
modulePathIgnorePatterns, | ||
testPathIgnorePatterns, | ||
watchPathIgnorePatterns, | ||
} = baseConfig; | ||
|
||
assert.strictEqual( | ||
testPathIgnorePatterns[0], | ||
'/test-types/', | ||
'First entry must be types', | ||
); | ||
|
||
module.exports = { | ||
displayName: { | ||
color: 'blue', | ||
name: 'types', | ||
}, | ||
modulePathIgnorePatterns, | ||
runner: 'jest-runner-tsd', | ||
testMatch: ['<rootDir>/test-types/*.test.ts'], | ||
testPathIgnorePatterns: testPathIgnorePatterns.slice(1), | ||
watchPathIgnorePatterns, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* 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. | ||
* | ||
* This has to be a empty file | ||
* @see https://github.com/MLH-Fellowship/jest-runner-tsd/blob/e25720040939fc79ab38d73c1495be90d5b92566/README.md#for-typescript-projects | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* 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 {expectError, expectType} from 'mlh-tsd'; | ||
//eslint-disable-next-line import/no-extraneous-dependencies | ||
import {jest} from '@jest/globals'; | ||
|
||
expectType<void>(jest.addMatchers({})); | ||
expectType<typeof jest>(jest.autoMockOff()); | ||
expectType<typeof jest>(jest.autoMockOn()); | ||
expectType<typeof jest>(jest.clearAllMocks()); | ||
expectType<void>(jest.clearAllTimers()); | ||
expectType<typeof jest>(jest.resetAllMocks()); | ||
expectType<typeof jest>(jest.restoreAllMocks()); | ||
expectType<void>(jest.clearAllTimers()); | ||
expectType<typeof jest>(jest.deepUnmock('moduleName')); | ||
expectType<typeof jest>(jest.disableAutomock()); | ||
expectType<typeof jest>(jest.doMock('moduleName')); | ||
expectType<typeof jest>(jest.doMock('moduleName', jest.fn())); | ||
|
||
expectError(jest.doMock('moduleName', jest.fn(), {})); | ||
expectError(jest.doMock('moduleName', jest.fn(), {virtual: true})); | ||
|
||
expectType<typeof jest>(jest.dontMock('moduleName')); | ||
expectType<typeof jest>(jest.enableAutomock()); | ||
expectType<typeof jest>(jest.mock('moduleName')); | ||
expectType<typeof jest>(jest.mock('moduleName', jest.fn())); | ||
expectType<typeof jest>(jest.mock('moduleName', jest.fn(), {})); | ||
expectType<typeof jest>(jest.mock('moduleName', jest.fn(), {virtual: true})); | ||
expectType<typeof jest>(jest.resetModuleRegistry()); | ||
expectType<typeof jest>(jest.resetModules()); | ||
expectType<typeof jest>(jest.isolateModules(() => {})); | ||
expectType<typeof jest>(jest.retryTimes(3)); | ||
|
||
expectType<void>(jest.runAllImmediates()); | ||
expectType<void>(jest.runAllTicks()); | ||
expectType<void>(jest.runAllTimers()); | ||
expectType<void>(jest.runOnlyPendingTimers()); | ||
expectType<void>(jest.runTimersToTime(9001)); | ||
expectType<void>(jest.advanceTimersByTime(9001)); | ||
|
||
expectType<typeof jest>(jest.setMock('moduleName', {})); | ||
expectType<typeof jest>(jest.setMock('moduleName', {})); | ||
expectType<typeof jest>(jest.setMock('moduleName', {a: 'b'})); | ||
expectType<typeof jest>(jest.setTimeout(9001)); | ||
expectType<typeof jest>(jest.unmock('moduleName')); | ||
expectType<typeof jest>(jest.useFakeTimers()); | ||
expectType<typeof jest>(jest.useRealTimers()); | ||
|
||
expectType<void>(jest.advanceTimersToNextTimer()); | ||
expectType<void>(jest.advanceTimersToNextTimer(2)); | ||
|
||
// https://jestjs.io/docs/en/jest-object#jestusefaketimersimplementation-modern--legacy | ||
expectType<typeof jest>(jest.useFakeTimers('modern')); | ||
expectType<typeof jest>(jest.useFakeTimers('legacy')); | ||
|
||
expectError(jest.useFakeTimers('foo')); | ||
|
||
// https://jestjs.io/docs/en/jest-object#jestsetsystemtimenow-number--date | ||
expectType<void>(jest.setSystemTime()); | ||
expectType<void>(jest.setSystemTime(0)); | ||
expectType<void>(jest.setSystemTime(new Date(0))); | ||
|
||
expectError(jest.setSystemTime('foo')); | ||
|
||
// https://jestjs.io/docs/en/jest-object#jestgetrealsystemtime | ||
expectType<number>(jest.getRealSystemTime()); | ||
|
||
expectError(jest.getRealSystemTime('foo')); | ||
|
||
// https://jestjs.io/docs/en/jest-object#jestrequireactualmodulename | ||
expectType<unknown>(jest.requireActual('./thisReturnsTheActualModule')); | ||
|
||
// https://jestjs.io/docs/en/jest-object#jestrequiremockmodulename | ||
expectType<unknown>(jest.requireMock('./thisAlwaysReturnsTheMock')); |
Oops, something went wrong.