mocking (directions) calls using nock
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 768
- Forks
- 191
- PR merge metrics
- No merged PRs in 30d
Description
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:
```ts
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the Jest test where nock.recorder.rec() captures the directions request, then compare the recorded response with what the SDK expects. Investigate why this mock produces "Request aborted" and use the directions-call test to verify that a representative mocked response completes successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- api, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 45/100