Socket
Socket
Sign inDemoInstall

nock

Package Overview
Dependencies
3
Maintainers
4
Versions
423
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 13.3.8 to 13.4.0

17

lib/back.js

@@ -243,2 +243,19 @@ 'use strict'

},
query: function () {
const nested = this.scopes.map(scope =>
scope.interceptors.map(interceptor => ({
method: interceptor.method,
uri: interceptor.uri,
basePath: interceptor.basePath,
path: interceptor.path,
queries: interceptor.queries,
counter: interceptor.counter,
body: interceptor.body,
statusCode: interceptor.statusCode,
optional: interceptor.optional,
})),
)
return [].concat.apply([], nested)
},
}

@@ -245,0 +262,0 @@

2

package.json

@@ -10,3 +10,3 @@ {

],
"version": "13.3.8",
"version": "13.4.0",
"author": "Pedro Teixeira <pedro.teixeira@gmail.com>",

@@ -13,0 +13,0 @@ "repository": {

@@ -1500,2 +1500,41 @@ # Nock

### Verifying recorded fixtures
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.
The `context.query` function can be used to return all of the interceptors that were recored in a given fixture.
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.
**NB**: The list of fixtures is only available when reading. It will only be populated for nocks that are played back from fixtures.
#### Example
```js
it('#synchronize - synchronize with the external API', async localState => {
const { nockDone, context } = await back('http-interaction.json')
const syncronizer = new Synchronizer(localState)
sycnronizer.syncronize()
nockDone()
context.assertScopesFinished()
expect(context.query()).toEqual(
expect.arrayContaining([
expect.objectContaining({
method: 'POST',
path: '/create/thing',
}),
expect.objectContaining({
method: 'POST',
path: 'create/thing',
}),
]),
)
})
```
## Common issues

@@ -1502,0 +1541,0 @@

@@ -270,2 +270,14 @@ // TypeScript Version: 3.5

interface InterceptorSurface {
method: string
uri: string
basePath: string
path: string
queries?: string
counter: number
body: string
statusCode: number
optional: boolean
}
interface BackContext {

@@ -275,2 +287,3 @@ isLoaded: boolean

assertScopesFinished(): void
query: InterceptorSurface[]
}

@@ -277,0 +290,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc