Skip to content

Mocking an error and using retry() #93

@techandsoftware

Description

@techandsoftware

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions