vue-jest
vue-jest copied to clipboard
Error about the 'A list of blog posts' chapter
https://next.vue-test-utils.vuejs.org/guide/advanced/http-requests.html#a-list-of-blog-posts
// Following lines tell Jest to mock any call to `axios.get`
// and to return `mockPostList` instead
jest.mock('axios', () => ({
get: jest.fn(() => mockPostList)
}))
The demo in this chapter failed on my laptop.

seems axios finished before starting to find the [role="alert"] element.

I'm using "jest": "^27.4.5",
Jest mock seems to make the axios get a sync function, which was async.
jest.mock('axios', () => ({
get: jest.fn(() => mockPostList)
}))
So, if I make the mock function async, the test will pass.
jest.mock("axios", () => ({
get: jest.fn(async () => {
await Promise.resolve().then(); //nextTick() will be the same
return mockPostList;
}),
}));
And, maybe it's not the right place. But as a beginner, I wish I can dive into this project deeper. Sadlly I don't know where to start. Would it be a bother asking you to give me some advice?