How do you confirm that the request was made using axios-mock-adapter?

I am using https://github.com/ctimmerm/axios-mock-adapter

I would like to know how I can verify that the endpoint was actually caused by the system under test.

In this example:

var axios = require('axios');
var MockAdapter = require('axios-mock-adapter');

// This sets the mock adapter on the default instance
var mock = new MockAdapter(axios);

// Mock any GET request to /users
// arguments for reply are (status, data, headers)
mock.onGet('/users').reply(200, {
  users: [
    { id: 1, name: 'John Smith' }
  ]
});

How can I find out if the "/ users" call is called?

I am looking for something similar to what you can do in Jest:

expect(mockFunc).toHaveBeenCalledTimes(1)

I understand that I can use some user logic when using the function to respond and set a local variable indicating whether the request was completed. I'm just wondering if there is a cleaner way to do this.

+4
source share
1 answer

acios-mock-adapter, , , jest, jest.spyOn.

let spy = jest.spyOn(axios, "get");
//run http request here
expect(spy).toHaveBeenCalled();

: , , , , setTimeout (function, 0),

0

Source: https://habr.com/ru/post/1690441/


All Articles