Skip to content

Commit

Permalink
remove docs changes
Browse files Browse the repository at this point in the history
  • Loading branch information
k-rajat19 committed Dec 8, 2021
1 parent 96dd2c3 commit 3094fdf
Showing 1 changed file with 0 additions and 41 deletions.
41 changes: 0 additions & 41 deletions website/versioned_docs/version-27.2/JestObjectAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -578,47 +578,6 @@ Returns the `jest` object for chaining.

Restores all mocks back to their original value. Equivalent to calling [`.mockRestore()`](MockFunctionAPI.md#mockfnmockrestore) on every mocked function. Beware that `jest.restoreAllMocks()` only works when the mock was created with `jest.spyOn`; other mocks will require you to manually restore them.

### `jest.mocked<T>(item: T, deep = false)`

The `mocked` test helper provides typings on your mocked modules and even their deep methods, based on the typing of its source. It makes use of the latest TypeScript feature, so you even have argument types completion in the IDE (as opposed to `jest.MockInstance`).

_Note: while it needs to be a function so that input type is changed, the helper itself does nothing else than returning the given input value._

Example:

```ts
// foo.ts
export const foo = {
a: {
b: {
c: {
hello: (name: string) => `Hello, ${name}`,
},
},
},
name: () => 'foo',
};
```

```ts
// foo.spec.ts
import {foo} from './foo';
jest.mock('./foo');
// here the whole foo var is mocked deeply
const mockedFoo = jest.mocked(foo, true);
test('deep', () => {
// there will be no TS error here, and you'll have completion in modern IDEs
mockedFoo.a.b.c.hello('me');
// same here
expect(mockedFoo.a.b.c.hello.mock.calls).toHaveLength(1);
});
test('direct', () => {
foo.name();
// here only foo.name is mocked (or its methods if it's an object)
expect(mocked(foo.name).mock.calls).toHaveLength(1);
});
```

## Mock Timers

### `jest.useFakeTimers(implementation?: 'modern' | 'legacy')`
Expand Down

0 comments on commit 3094fdf

Please sign in to comment.