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 (directions) calls using nock #443

Open
boredland opened this issue Jun 29, 2022 · 1 comment
Open

mocking (directions) calls using nock #443

boredland opened this issue Jun 29, 2022 · 1 comment

Comments

@boredland
Copy link

hi there! I currently struggle to mock the directions API using nock, perhaps someone here has an idea how to achieve this?

you can generate a mock using nock quite easily by just inserting nock.recorder.rec(); in a jest test.

the generated code looks like this:

nock('https://api.mapbox.com:443', { encodedQueryParams: true })
  .get(
    '/directions/v5/mapbox/driving/8.767828%2C50.15727%3B8.761143%2C50.15661%3B8.759261..',
  )
  .query({
    alternatives: 'false',
    continue_straight: 'true',
    geometries: 'geojson',
    overview: 'full',
    steps: 'false',
    access_token:
      'pk.xxx.xxx',
  })
  .reply(
    200,
    [
      '1f8b0800000000000003cd5aed6e5bc7117d15.....gzipped response payload',
    ],
    [
      'Content-Type',
      'application/json; charset=utf-8',
      'Transfer-Encoding',
      'chunked',
      'Connection',
      'close',
      'Date',
      'Wed, 29 Jun 2022 17:34:29 GMT',
      'Access-Control-Allow-Origin',
      '*',
      'x-mapbox-request-id',
      'xxx==',
      'Cache-Control',
      'max-age=3600',
      'x-mapbox-routing-engine',
      'v2.0',
      'Content-Encoding',
      'gzip',
      'Vary',
      'Accept-Encoding',
      'X-Cache',
      'Hit from cloudfront',
      'Via',
      '1.1 xxx.cloudfront.net (CloudFront)',
      'X-Amz-Cf-Pop',
      'FRA50-C1',
      'X-Amz-Cf-Id',
      'xxx',
      'Age',
      '1657',
    ],
  );

while this mock catches the request as it should, the sdk emits just "Request aborted". So something is not like it expects it to be in the response. Any ideas?

@boredland
Copy link
Author

my current assumption is, that this is mainly an issue with nock.

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

1 participant