---
title: "Discussion on \"Mocking in Jest with TypeScript and React\" | Hashnode"
description: "Discussion on \"Mocking in Jest with TypeScript and React\". It is functions all the way down"
url: "https://hashnode.com/posts/mocking-in-jest-with-typescript-and-react/60e06c0903707d644a50080d"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Mocking in Jest with TypeScript and React](https://blog.rupertmckay.com/mocking-in-jest-with-typescript-and-react?utm_source=hashnode&utm_medium=feed)

It is functions all the way down

Jul 3, 2021 · 11 min read · blog.rupertmckay.com  
Read the article

-   [#jest](https://hashnode.com/tag/jest)
-   [#typescript](https://hashnode.com/tag/typescript)
-   [#reactjs](https://hashnode.com/tag/reactjs)
-   [#testing](https://hashnode.com/tag/testing)
-   [#testing-library](https://hashnode.com/tag/testing-library)

## Written by

[Rupert McKay](https://hashnode.com/@fildon)

@fildon · Delft, The Netherlands

  
[View profile](https://hashnode.com/@fildon)

Staff Software Engineer at Lokalise

## Responses 2

Markdown supported · ⌘↵ to post

[Lars Ejaas](https://hashnode.com/@LarsEjaas)

[Jan 23, 2022](https://hashnode.com/posts/mocking-in-jest-with-typescript-and-react/60e06c0903707d644a50080d/comment/61ed5d8aa12088017fbec05a)

Hi Rubert

Finally got to try this out in a project. I am however struggling with the following error:

```
TypeError: xxxxx.mockImplementation is not a function
```

Have you seen something like this before? Do you need to setup something specifically to handle mocks in jest.setup.ts or jest.config.js?

[Rupert McKay](https://hashnode.com/@fildon)

[Jan 24, 2022](https://hashnode.com/posts/mocking-in-jest-with-typescript-and-react/60e06c0903707d644a50080d/comment/61ed5d8aa12088017fbec05a#reply-61ee5cebc99aed184e726586)

In general, any time you see "foo is not a function" that suggests that you have an undefined reference.

If you've followed along with the post above, the possible points of failure are either forgetting to `jest.mock` the relevant module path (e.g. `jest.mock('my/path')`) or forgetting to cast a mock type using the original type as the base (e.g. `const mockFoo = foo as jest.MockedFunction<typeof foo>`).

[Lars Ejaas](https://hashnode.com/@LarsEjaas)

[Jan 24, 2022](https://hashnode.com/posts/mocking-in-jest-with-typescript-and-react/60e06c0903707d644a50080d/comment/61ed5d8aa12088017fbec05a#reply-61ee6415c99aed184e726692)

[Rupert 'fildon' McKay](https://hashnode.com/@fildon) Thanks Rupert. I will give it another go! I have another syntax to use, but yours looks so much more elegant, and I sometimes get edgecases where your pattern would be very helpful. Thanks again for a great article! There is way to little material out there on writing good tests. Best regards Lars

[WackyJacky](https://hashnode.com/@WackyJacky)

[Jul 3, 2021](https://hashnode.com/posts/mocking-in-jest-with-typescript-and-react/60e06c0903707d644a50080d/comment/60e0c6034f8e376422a78594)

I happened to be looking for Jest.mock in Medium and Dev.to, but couldn't find an Article as good as this one explained. Thank you Rupert for sharing such insightful article!
