diff --git a/src/response.ts b/src/response.ts index 77101ac..2fc7656 100644 --- a/src/response.ts +++ b/src/response.ts @@ -344,6 +344,15 @@ export class ApiResponse extends Macroable { this.assert!.containsSubset(this.body(), expectedBody) } + /** + * Assert response body not to match the subset from the + * expected body + */ + public assertBodyNotContains(expectedBody: any) { + this.ensureHasAssert() + this.assert!.notContainsSubset(this.body(), expectedBody) + } + /** * Assert response to contain a given cookie and optionally * has the expected value diff --git a/tests/response/assertions.spec.ts b/tests/response/assertions.spec.ts index 958c1ea..12c5c02 100644 --- a/tests/response/assertions.spec.ts +++ b/tests/response/assertions.spec.ts @@ -97,6 +97,24 @@ test.group('Response | assertions', (group) => { response.assertBodyContains([{ message: 'hello world' }, { message: 'hi world' }]) }) + test('assert response body not subset', async ({ assert }) => { + assert.plan(1) + + httpServer.onRequest((_, res) => { + res.statusCode = 200 + res.setHeader('content-type', 'application/json') + res.end(JSON.stringify([{ message: 'hello world', time: new Date() }])) + }) + + const request = new ApiRequest( + { baseUrl: httpServer.baseUrl, method: 'GET', endpoint: '/' }, + assert + ) + + const response = await request + response.assertBodyNotContains([{ message: 'hi world' }]) + }) + test('assert response body when response is not json', async ({ assert }) => { httpServer.onRequest((_, res) => { res.statusCode = 401