Comparing version 13.3.6 to 13.4.0
@@ -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 @@ |
@@ -10,3 +10,3 @@ { | ||
], | ||
"version": "13.3.6", | ||
"version": "13.4.0", | ||
"author": "Pedro Teixeira <pedro.teixeira@gmail.com>", | ||
@@ -32,3 +32,3 @@ "repository": { | ||
"@definitelytyped/dtslint": "^0.0.163", | ||
"@sinonjs/fake-timers": "^10.0.0", | ||
"@sinonjs/fake-timers": "^11.2.2", | ||
"assert-rejects": "^1.0.0", | ||
@@ -64,3 +64,3 @@ "chai": "^4.1.2", | ||
"lint:ts": "dtslint --expectOnly types", | ||
"test": "nyc --reporter=lcov --reporter=text mocha tests", | ||
"test": "nyc --reporter=lcov --reporter=text mocha --recursive tests", | ||
"test:coverage": "open coverage/lcov-report/index.html" | ||
@@ -67,0 +67,0 @@ }, |
@@ -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 @@ |
@@ -121,3 +121,5 @@ // TypeScript Version: 3.5 | ||
filteringRequestBody(regex: RegExp, replace: string): this | ||
filteringRequestBody(fn: (body: string) => string): this | ||
filteringRequestBody( | ||
fn: (body: string, recordedBody: string) => string, | ||
): this | ||
@@ -269,2 +271,14 @@ persist(flag?: boolean): this | ||
interface InterceptorSurface { | ||
method: string | ||
uri: string | ||
basePath: string | ||
path: string | ||
queries?: string | ||
counter: number | ||
body: string | ||
statusCode: number | ||
optional: boolean | ||
} | ||
interface BackContext { | ||
@@ -274,2 +288,3 @@ isLoaded: boolean | ||
assertScopesFinished(): void | ||
query: InterceptorSurface[] | ||
} | ||
@@ -276,0 +291,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
185494
3613
1715