Skip to content

Commit 307464e

Browse files
committed
feat(REST): add header assertion
1 parent 812f0bf commit 307464e

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/REST.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ void describe('REST', () => {
4747
},
4848
)
4949

50+
scope.get('/header-response').reply(200, undefined, {
51+
'x-foo': 'bar',
52+
})
53+
5054
const runner = await runFolder({
5155
folder: path.join(__dirname, 'test-data', 'REST'),
5256
name: 'REST',

src/REST.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,21 @@ export const steps: StepRunner<Record<string, any>>[] = [
107107
)
108108
},
109109
),
110+
regExpMatchedStep(
111+
{
112+
regExp:
113+
/^the `(?<headerName>[^`]+)` header of the last response should be `(?<headerValue>[^`]+)`$/,
114+
schema: Type.Object({
115+
headerName: Type.String({ minLength: 1 }),
116+
headerValue: Type.String({ minLength: 1 }),
117+
}),
118+
},
119+
async ({ match: { headerName, headerValue } }) => {
120+
await currentRequest.match(async ({ response }) =>
121+
assert.equal(response.headers.get(headerName), headerValue),
122+
)
123+
},
124+
),
110125
regExpMatchedStep(
111126
{
112127
regExp:

src/test-data/REST/REST.feature.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,9 @@ Then I should receive a
2424
`https://github.com/hello-nrfcloud/bdd-markdown-steps/tests` response
2525

2626
And the status code of the last response should be `200`
27+
28+
## Reading headers
29+
30+
When I `GET` to `${endpoint}/header-response`
31+
32+
Then the `x-foo` header of the last response should be `bar`

0 commit comments

Comments
 (0)