A / superagent-mocker

Pretty simple in-browser mocks for CRUD and REST API
132 stars 32 forks source link

Incorrect mocking of `req.query`. #54

Open AlexChalk opened 6 years ago

AlexChalk commented 6 years ago

If I use superagent and set query to { foo: undefined, bar: [], baz: false, quux: ['a', 'b'] }, superagent-mock generates a req.query object of { foo: 'undefined', bar: '', baz: 'false', quux: 'a,b' }. However, in reality my api receives a query object of { baz: 'false', quux: ['a', 'b'] }.

Steps to reproduce:

  1. Write mock for a superagent request:
    mock.get(...api-address..., (req) => {
    console.log(req.query);
    return { status: 200 };
    });
  2. Write request and verify that { foo: 'undefined', bar: '', baz: 'false', quux: 'a,b' } is logged to console:
    request
    .get(`...api-address...`)
    .query({ foo: undefined, bar: [], baz: false, quux: ['a', 'b'] })
  3. Send the request to your server and log req.query, confirm it equals { baz: 'false', quux: ['a', 'b'] }.