Skip to content

Commit e74619a

Browse files
committed
feat(rest): add status code matcher
1 parent 6d43f83 commit e74619a

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/REST.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,20 @@ export const steps: StepRunner<Record<string, any>>[] = [
7070
)
7171
},
7272
),
73+
regExpMatchedStep(
74+
{
75+
regExp:
76+
/^the status code of the last response should be `(?<statusCode>[^`]+)`$/,
77+
schema: Type.Object({
78+
statusCode: Type.RegExp(/^\d+$/),
79+
}),
80+
},
81+
async ({ match: { statusCode } }) => {
82+
await currentRequest.match(async ({ response }) =>
83+
check(parseInt(statusCode, 10)).is(response.status),
84+
)
85+
},
86+
),
7387
regExpMatchedStep(
7488
{
7589
regExp:

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ When I `GET` `${endpoint}/foo`
1111

1212
Then I should receive a
1313
`https://github.com/hello-nrfcloud/bdd-markdown-steps/tests` response
14+
15+
And the status code of the last response should be `200`

0 commit comments

Comments
 (0)