nock 13.3.8 → 13.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1497,6 +1497,45 @@ To set the mode call `nockBack.setMode(mode)` or run the tests with the `NOCK_BA
1497
1497
 
1498
1498
  - lockdown: use recorded nocks, disables all http calls even when not nocked, doesn't record
1499
1499
 
1500
+ ### Verifying recorded fixtures
1501
+
1502
+ Although you can certainly open the recorded JSON fixtures to manually verify requests recorded by nockBack - it's sometimes useful to put those expectations in your tests.
1503
+
1504
+ The `context.query` function can be used to return all of the interceptors that were recored in a given fixture.
1505
+
1506
+ By itself, this functions as a negative expectation - you can verify that certain calls do NOT happen in the fixture. Since `assertScopesFinished` can verify there are no _extra_ calls in a fixture - pairing the two methods allows you to verify the exact set of HTTP interactions recorded in the fixture. This is especially useful when re-recording for instance, a service that synchronizes via several HTTP calls to an external API.
1507
+
1508
+ **NB**: The list of fixtures is only available when reading. It will only be populated for nocks that are played back from fixtures.
1509
+
1510
+ #### Example
1511
+
1512
+ ```js
1513
+ it('#synchronize - synchronize with the external API', async localState => {
1514
+ const { nockDone, context } = await back('http-interaction.json')
1515
+
1516
+ const syncronizer = new Synchronizer(localState)
1517
+
1518
+ sycnronizer.syncronize()
1519
+
1520
+ nockDone()
1521
+
1522
+ context.assertScopesFinished()
1523
+
1524
+ expect(context.query()).toEqual(
1525
+ expect.arrayContaining([
1526
+ expect.objectContaining({
1527
+ method: 'POST',
1528
+ path: '/create/thing',
1529
+ }),
1530
+ expect.objectContaining({
1531
+ method: 'POST',
1532
+ path: 'create/thing',
1533
+ }),
1534
+ ]),
1535
+ )
1536
+ })
1537
+ ```
1538
+
1500
1539
  ## Common issues
1501
1540
 
1502
1541
  **"No match for response" when using got with error responses**
package/lib/back.js CHANGED
@@ -240,6 +240,23 @@ function load(fixture, options) {
240
240
  assertScopesFinished: function () {
241
241
  assertScopes(this.scopes, fixture)
242
242
  },
243
+ query: function () {
244
+ const nested = this.scopes.map(scope =>
245
+ scope.interceptors.map(interceptor => ({
246
+ method: interceptor.method,
247
+ uri: interceptor.uri,
248
+ basePath: interceptor.basePath,
249
+ path: interceptor.path,
250
+ queries: interceptor.queries,
251
+ counter: interceptor.counter,
252
+ body: interceptor.body,
253
+ statusCode: interceptor.statusCode,
254
+ optional: interceptor.optional,
255
+ })),
256
+ )
257
+
258
+ return [].concat.apply([], nested)
259
+ },
243
260
  }
244
261
 
245
262
  if (fixture && fixtureExists(fixture)) {
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "testing",
8
8
  "isolation"
9
9
  ],
10
- "version": "13.3.8",
10
+ "version": "13.4.0",
11
11
  "author": "Pedro Teixeira <pedro.teixeira@gmail.com>",
12
12
  "repository": {
13
13
  "type": "git",
package/types/index.d.ts CHANGED
@@ -267,10 +267,23 @@ declare namespace nock {
267
267
  }>
268
268
  }
269
269
 
270
+ interface InterceptorSurface {
271
+ method: string
272
+ uri: string
273
+ basePath: string
274
+ path: string
275
+ queries?: string
276
+ counter: number
277
+ body: string
278
+ statusCode: number
279
+ optional: boolean
280
+ }
281
+
270
282
  interface BackContext {
271
283
  isLoaded: boolean
272
284
  scopes: Scope[]
273
285
  assertScopesFinished(): void
286
+ query: InterceptorSurface[]
274
287
  }
275
288
 
276
289
  interface BackOptions {