score:0

export default function HomePage (){}

it('axios mock', async () => {
    let wrapper;
    
    axios.get = jest.fn()
    jest.mock('Axios');

    const data = [
        {
          "userId": 1,
          "id": 1,
          "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
          "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
        }
      ]
    
      await act(async ()=> {
        await axios.get.mockImplementationOnce(()=> Promise.resolve(data))
        wrapper = mount(<HomePage />)
      })
    
    await expect(axios.get).toHaveBeenCalledTimes(1);
    wrapper.update();
    await expect(axios.get).toHaveBeenCalledWith('https://jsonplaceholder.typicode.com/posts?_limit=5')
    await expect(wrapper.find("Post").at(0)).toHaveLength(1)
    expect(toJson(wrapper)).toMatchSnapshot();
  
  })

Related Query

More Query from same tag