jameslnewell / xhr-mock

Utility for mocking XMLHttpRequest.
196 stars 48 forks source link

Calling timeout function with any arguments throws an exception #31

Closed dfedynich closed 6 years ago

dfedynich commented 6 years ago

Hello, @jameslnewell .

What's Up

I want to simulate a time gap to get the response. To achieve this goal I use .timeout(timeout : bool|number) function according to your spec. However the call of this function with any arguments throws the exception 'timeout of 0ms exceeded'

Example

var mock = require('xhr-mock');
mock.setup();

mock.get(/(api\/users).*/, function(req, res) {
  return res.timeout(1000).status(200).body('<h1>Google</h1>');
});

var axios = require('axios');
axios({url: 'api/users'}).then(
  function(res) {
    console.log('loaded', res.data);
  },
  function(error) {
    console.log('ERROR', error);
  }
);
jameslnewell commented 6 years ago

Hi @dfedynich. Can you please try xhr-mock@next where a timeout looks like (req, res) => new Promise(() => {});

jameslnewell commented 6 years ago

any luck @dfedynich?