Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocking an error and using retry() #93

Open
techandsoftware opened this issue Feb 13, 2020 · 4 comments
Open

Mocking an error and using retry() #93

techandsoftware opened this issue Feb 13, 2020 · 4 comments

Comments

@techandsoftware
Copy link

I'm trying to do the following

  1. Get a fixture to return a server error (500)
  2. Use retry(3) on the superagent
  3. See that the fixture is called 3 times, and the get request ultimately fails.

I've written a small test script, from what it looks like the failure happens immediately after the exeption even though the retry callback is called 3 times afterwards.

Here's my script

var request = require('superagent');
var config = [{
  pattern: 'http://localhost/500/devices',
  fixtures: (match, params) => {
    let err = new Error(500);
    err.status = 500;
    throw err;
  },
  get: (match, data) => {
      return data;
  }
}];


var superagentMock = require('superagent-mock')(request, config);

request
  .get('http://localhost/500/devices')
  .retry(3, retryCallback)
  .then(res => {
    console.log('completed');
   	console.log(res);
  })
  .catch(err => {
    console.log('failed');
    console.log(err);
  });


function retryCallback(err, res) {
  console.debug('__retrying');
  return true;
}

Output is
failed
__retrying
__retrying
__retrying

Is there an error with how superagent-mock interacts with retry or am I approaching this the wrong way?

@fdubost
Copy link
Member

fdubost commented Feb 14, 2020

Hi, did you test to throw the error in the get method instead in the fixtures?

@techandsoftware
Copy link
Author

Yes, the result is the same.

@fdubost
Copy link
Member

fdubost commented Feb 18, 2020

I think the problem is with superagent-mock that don't handle superagent's retry method. We don't use the retry feature of superagent, but feel free to open a PR to fix this bug 😉

@techandsoftware
Copy link
Author

I'll try and work it out :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants