From c010e3597dbd021d7fe88060ecbe282fe29a8d3d Mon Sep 17 00:00:00 2001 From: Tom Mrazauskas Date: Tue, 17 Jan 2023 08:39:53 +0200 Subject: [PATCH] refactor(@jest/environment): keep alphabetic order in the `Jest` interface (#13773) --- docs/JestObjectAPI.md | 40 +++++++++++----------- packages/jest-environment/src/index.ts | 46 ++++++++++++++------------ 2 files changed, 44 insertions(+), 42 deletions(-) diff --git a/docs/JestObjectAPI.md b/docs/JestObjectAPI.md index d52af3d7c0b0..43d580e543f7 100644 --- a/docs/JestObjectAPI.md +++ b/docs/JestObjectAPI.md @@ -555,10 +555,6 @@ test('works too', () => { Returns the `jest` object for chaining. -### `jest.isEnvironmentTornDown(fn)` - -Returns `true` if test environment has been torn down. - ### `jest.isolateModules(fn)` `jest.isolateModules(fn)` goes a step further than `jest.resetModules()` and creates a sandbox registry for the modules that are loaded inside the callback function. This is useful to isolate specific modules for every test so that local module state doesn't conflict between tests. @@ -993,23 +989,9 @@ Use the [`--showSeed`](CLI.md#--showseed) flag to print the seed in the test rep ::: -### `jest.setTimeout(timeout)` - -Set the default timeout interval (in milliseconds) for all tests and before/after hooks in the test file. This only affects the test file from which this function is called. The default timeout interval is 5 seconds if this method is not called. - -Example: +### `jest.isEnvironmentTornDown()` -```js -jest.setTimeout(1000); // 1 second -``` - -:::tip - -To set timeout intervals on different tests in the same file, use the [`timeout` option on each individual test](GlobalAPI.md#testname-fn-timeout). - -If you want to set the timeout for all test files, use [`testTimeout`](Configuration.md#testtimeout-number) configuration option. - -::: +Returns `true` if test environment has been torn down. ### `jest.retryTimes(numRetries, options)` @@ -1034,3 +1016,21 @@ test('will fail', () => { ``` Returns the `jest` object for chaining. + +### `jest.setTimeout(timeout)` + +Set the default timeout interval (in milliseconds) for all tests and before/after hooks in the test file. This only affects the test file from which this function is called. The default timeout interval is 5 seconds if this method is not called. + +Example: + +```js +jest.setTimeout(1000); // 1 second +``` + +:::tip + +To set timeout intervals on different tests in the same file, use the [`timeout` option on each individual test](GlobalAPI.md#testname-fn-timeout). + +If you want to set the timeout for all test files, use [`testTimeout`](Configuration.md#testtimeout-number) configuration option. + +::: diff --git a/packages/jest-environment/src/index.ts b/packages/jest-environment/src/index.ts index bbf86340e0fe..06df69671e14 100644 --- a/packages/jest-environment/src/index.ts +++ b/packages/jest-environment/src/index.ts @@ -157,23 +157,22 @@ export interface Jest { * Returns the number of fake timers still left to run. */ getTimerCount(): number; - /** - * Returns the current time in ms of the fake timer clock. - */ - now(): number; - /** - * Determines if the given function is a mocked function. - */ - isMockFunction: ModuleMocker['isMockFunction']; /** * Returns `true` if test environment has been torn down. + * * @example + * ```js * if (jest.isEnvironmentTornDown()) { * // The Jest environment has been torn down, so stop doing work * return; * } + * ``` */ isEnvironmentTornDown(): boolean; + /** + * Determines if the given function is a mocked function. + */ + isMockFunction: ModuleMocker['isMockFunction']; /** * `jest.isolateModules()` goes a step further than `jest.resetModules()` and * creates a sandbox registry for the modules that are loaded inside the callback @@ -203,6 +202,23 @@ export interface Jest { moduleFactory: () => T | Promise, options?: {virtual?: boolean}, ): Jest; + /** + * Wraps types of the `source` object and its deep members with type definitions + * of Jest mock function. Pass `{shallow: true}` option to disable the deeply + * mocked behavior. + */ + mocked: ModuleMocker['mocked']; + /** + * Returns the current time in ms of the fake timer clock. + */ + now(): number; + /** + * Replaces property on an object with another value. + * + * @remarks + * For mocking functions or 'get' or 'set' accessors, use `jest.spyOn()` instead. + */ + replaceProperty: ModuleMocker['replaceProperty']; /** * Returns the actual module instead of a mock, bypassing all checks on * whether the module should receive a mock implementation or not. @@ -226,19 +242,6 @@ export interface Jest { * ``` */ requireActual(moduleName: string): T; - /** - * Wraps types of the `source` object and its deep members with type definitions - * of Jest mock function. Pass `{shallow: true}` option to disable the deeply - * mocked behavior. - */ - mocked: ModuleMocker['mocked']; - /** - * Replaces property on an object with another value. - * - * @remarks - * For mocking functions or 'get' or 'set' accessors, use `jest.spyOn()` instead. - */ - replaceProperty: ModuleMocker['replaceProperty']; /** * Returns a mock module instead of the actual module, bypassing all checks * on whether the module should be required normally or not. @@ -278,7 +281,6 @@ export interface Jest { numRetries: number, options?: {logErrorsBeforeRetry?: boolean}, ): Jest; - /** * Exhausts tasks queued by `setImmediate()`. *