Skip to content

Commit

Permalink
docs: fix one TypeScript example in Mock Functions documentation (#12520
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mrazauskas committed Mar 1, 2022
1 parent 59a7af7 commit 4067c51
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion docs/MockFunctionAPI.md
Expand Up @@ -137,6 +137,9 @@ Accepts a function that should be used as the implementation of the mock. The mo

:::

<Tabs groupId="examples">
<TabItem value="js" label="JavaScript">

```js
const mockFn = jest.fn(scalar => 42 + scalar);

Expand All @@ -149,7 +152,26 @@ mockFn(2); // 38
mockFn(3); // 39
```

`mockImplementation` can also be used to mock class constructors:
</TabItem>

<TabItem value="ts" label="TypeScript">

```js
const mockFn = jest.fn((scalar: number) => 42 + scalar);

mockFn(0); // 42
mockFn(1); // 43

mockFn.mockImplementation(scalar => 36 + scalar);

mockFn(2); // 38
mockFn(3); // 39
```

</TabItem>
</Tabs>

`.mockImplementation()` can also be used to mock class constructors:

<Tabs groupId="examples">
<TabItem value="js" label="JavaScript">
Expand Down

0 comments on commit 4067c51

Please sign in to comment.