Skip to content

Commit c010e35

Browse files
authored
refactor(@jest/environment): keep alphabetic order in the Jest interface (#13773)
1 parent 9ebb373 commit c010e35

File tree

2 files changed

+44
-42
lines changed

2 files changed

+44
-42
lines changed

docs/JestObjectAPI.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -555,10 +555,6 @@ test('works too', () => {
555555

556556
Returns the `jest` object for chaining.
557557

558-
### `jest.isEnvironmentTornDown(fn)`
559-
560-
Returns `true` if test environment has been torn down.
561-
562558
### `jest.isolateModules(fn)`
563559

564560
`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
993989

994990
:::
995991

996-
### `jest.setTimeout(timeout)`
997-
998-
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.
999-
1000-
Example:
992+
### `jest.isEnvironmentTornDown()`
1001993

1002-
```js
1003-
jest.setTimeout(1000); // 1 second
1004-
```
1005-
1006-
:::tip
1007-
1008-
To set timeout intervals on different tests in the same file, use the [`timeout` option on each individual test](GlobalAPI.md#testname-fn-timeout).
1009-
1010-
If you want to set the timeout for all test files, use [`testTimeout`](Configuration.md#testtimeout-number) configuration option.
1011-
1012-
:::
994+
Returns `true` if test environment has been torn down.
1013995

1014996
### `jest.retryTimes(numRetries, options)`
1015997

@@ -1034,3 +1016,21 @@ test('will fail', () => {
10341016
```
10351017

10361018
Returns the `jest` object for chaining.
1019+
1020+
### `jest.setTimeout(timeout)`
1021+
1022+
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.
1023+
1024+
Example:
1025+
1026+
```js
1027+
jest.setTimeout(1000); // 1 second
1028+
```
1029+
1030+
:::tip
1031+
1032+
To set timeout intervals on different tests in the same file, use the [`timeout` option on each individual test](GlobalAPI.md#testname-fn-timeout).
1033+
1034+
If you want to set the timeout for all test files, use [`testTimeout`](Configuration.md#testtimeout-number) configuration option.
1035+
1036+
:::

packages/jest-environment/src/index.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -157,23 +157,22 @@ export interface Jest {
157157
* Returns the number of fake timers still left to run.
158158
*/
159159
getTimerCount(): number;
160-
/**
161-
* Returns the current time in ms of the fake timer clock.
162-
*/
163-
now(): number;
164-
/**
165-
* Determines if the given function is a mocked function.
166-
*/
167-
isMockFunction: ModuleMocker['isMockFunction'];
168160
/**
169161
* Returns `true` if test environment has been torn down.
162+
*
170163
* @example
164+
* ```js
171165
* if (jest.isEnvironmentTornDown()) {
172166
* // The Jest environment has been torn down, so stop doing work
173167
* return;
174168
* }
169+
* ```
175170
*/
176171
isEnvironmentTornDown(): boolean;
172+
/**
173+
* Determines if the given function is a mocked function.
174+
*/
175+
isMockFunction: ModuleMocker['isMockFunction'];
177176
/**
178177
* `jest.isolateModules()` goes a step further than `jest.resetModules()` and
179178
* creates a sandbox registry for the modules that are loaded inside the callback
@@ -203,6 +202,23 @@ export interface Jest {
203202
moduleFactory: () => T | Promise<T>,
204203
options?: {virtual?: boolean},
205204
): Jest;
205+
/**
206+
* Wraps types of the `source` object and its deep members with type definitions
207+
* of Jest mock function. Pass `{shallow: true}` option to disable the deeply
208+
* mocked behavior.
209+
*/
210+
mocked: ModuleMocker['mocked'];
211+
/**
212+
* Returns the current time in ms of the fake timer clock.
213+
*/
214+
now(): number;
215+
/**
216+
* Replaces property on an object with another value.
217+
*
218+
* @remarks
219+
* For mocking functions or 'get' or 'set' accessors, use `jest.spyOn()` instead.
220+
*/
221+
replaceProperty: ModuleMocker['replaceProperty'];
206222
/**
207223
* Returns the actual module instead of a mock, bypassing all checks on
208224
* whether the module should receive a mock implementation or not.
@@ -226,19 +242,6 @@ export interface Jest {
226242
* ```
227243
*/
228244
requireActual<T = unknown>(moduleName: string): T;
229-
/**
230-
* Wraps types of the `source` object and its deep members with type definitions
231-
* of Jest mock function. Pass `{shallow: true}` option to disable the deeply
232-
* mocked behavior.
233-
*/
234-
mocked: ModuleMocker['mocked'];
235-
/**
236-
* Replaces property on an object with another value.
237-
*
238-
* @remarks
239-
* For mocking functions or 'get' or 'set' accessors, use `jest.spyOn()` instead.
240-
*/
241-
replaceProperty: ModuleMocker['replaceProperty'];
242245
/**
243246
* Returns a mock module instead of the actual module, bypassing all checks
244247
* on whether the module should be required normally or not.
@@ -278,7 +281,6 @@ export interface Jest {
278281
numRetries: number,
279282
options?: {logErrorsBeforeRetry?: boolean},
280283
): Jest;
281-
282284
/**
283285
* Exhausts tasks queued by `setImmediate()`.
284286
*

0 commit comments

Comments
 (0)