Thank you very much for your article, it helped me a lot.
I am having trouble replicating this with typescript, it complains when I try to set the mockResolvedValue into axios get.
Full stack developer building things to make life a little easier. Huge fan of JavaScript, React, Node.js, and testing my code. • twitter.com/ZakLaughton • zaklaughton.dev
Typescript isn't great at determining the types of mocked values, but there are some great libraries to help. Personally, I've had great success using the mocked method from ts-jest. See details and usage examples here: ts-jest/test-helpers
Hi Zak,
Thank you very much for your article, it helped me a lot.
I am having trouble replicating this with typescript, it complains when I try to set the mockResolvedValue into axios get.
test("it should return permission true", async() => {
axios.get.mockResolvedValue({ //type error here.
true
});
});
Hi Victor! Glad the article helped!
Typescript isn't great at determining the types of mocked values, but there are some great libraries to help. Personally, I've had great success using the
mocked
method from ts-jest. See details and usage examples here: ts-jest/test-helperstry (axios.get as jest.Mock).mockReturnValue({})