I created this repository because I was totally confused about how to use jest.mock()
with TypeScript.
First, I struggled with the official guide about how to use TypeScript in jest, which involved installing lots of babel packages and configuring it inside your project.
The next struggle was about how to access properties of the mock object from inside the test without type errors.
One thing that worked was telling TypeScript to shut up via //@ts-ignore
. But that didn't feel quite right.
The solution was to use ts-jest and the mocked
utility function from ts-jest/utils
as described in this Github issue comment. Saved my day :).
This program consumes the people/:id
endpoint from the Star Wars API and logs the output.
The test tests the implementation of the api function getPeople
.
The fetch call in the test is mocked.