diff --git a/autotests/tests/waitForResponse.ts b/autotests/tests/waitForResponse.ts index 57fe1b03..62553bc0 100644 --- a/autotests/tests/waitForResponse.ts +++ b/autotests/tests/waitForResponse.ts @@ -23,7 +23,7 @@ it( void addUser(); - const response = await waitForResponse( + let response = await waitForResponse( ({responseBody}: Response
) => responseBody?.name === 'John', ); @@ -38,5 +38,16 @@ it( }, () => undefined, ); + + void addUser(); + + response = await waitForResponse( + ({request}: Response) => request?.url === 'https://reqres.in/api/users', + ); + + await expect(response.responseBody, 'second response has correct body').contains({ + job: 'leader', + name: 'John', + }); }, ); diff --git a/src/constants/pages.ts b/src/constants/pages.ts index 3dcfac07..116eb4e0 100644 --- a/src/constants/pages.ts +++ b/src/constants/pages.ts @@ -1,4 +1,4 @@ /** * Unique token for creating page instances. */ -export const CREATE_PAGE_TOKEN = Symbol('Unique token for creating page instances'); +export const CREATE_PAGE_TOKEN = Symbol('e2ed:CREATE_PAGE_TOKEN'); diff --git a/src/constants/requestHook.ts b/src/constants/requestHook.ts index 1fddceeb..94d7f4f0 100644 --- a/src/constants/requestHook.ts +++ b/src/constants/requestHook.ts @@ -14,9 +14,9 @@ export const INCLUDE_HEADERS_IN_RESPONSE_EVENT = {includeHeaders: true} as const /** * Key for id of TestCafe's request hook context. */ -export const REQUEST_HOOK_CONTEXT_ID_KEY = Symbol('Key for id of request hook context'); +export const REQUEST_HOOK_CONTEXT_ID_KEY = Symbol('e2ed:REQUEST_HOOK_CONTEXT_ID_KEY'); /** * Key for TestCafe's request hook context on request hook events. */ -export const REQUEST_HOOK_CONTEXT_KEY = Symbol('Key for request hook context'); +export const REQUEST_HOOK_CONTEXT_KEY = Symbol('e2ed:REQUEST_HOOK_CONTEXT_KEY'); diff --git a/src/constants/selector.ts b/src/constants/selector.ts index 4911ac93..7f901169 100644 --- a/src/constants/selector.ts +++ b/src/constants/selector.ts @@ -1,4 +1,4 @@ /** * Key for string description of Selector. */ -export const DESCRIPTION_KEY = Symbol.for('e2ed:Key for string description of Selector'); +export const DESCRIPTION_KEY = Symbol.for('e2ed:DESCRIPTION_KEY'); diff --git a/src/types/http/http.ts b/src/types/http/http.ts index 0881886c..2023ae14 100644 --- a/src/types/http/http.ts +++ b/src/types/http/http.ts @@ -79,13 +79,15 @@ export type Request< }>; /** - * HTTP response object. + * HTTP response object with its corresponding request.. */ export type Response< ResponseBody = unknown, ResponseHeaders extends Headers = Headers, SomeStatusCode extends StatusCode = StatusCode, + SomeRequest extends Request = Request, > = Readonly<{ + request?: SomeRequest; responseBody: ResponseBody; responseHeaders: ResponseHeaders; statusCode: SomeStatusCode; diff --git a/src/utils/report/client/sanitizeHtml.ts b/src/utils/report/client/sanitizeHtml.ts index aaf15ee9..71b5d004 100644 --- a/src/utils/report/client/sanitizeHtml.ts +++ b/src/utils/report/client/sanitizeHtml.ts @@ -13,7 +13,7 @@ export function createSafeHtmlWithoutSanitize( stringParts: readonly string[], ...values: readonly unknown[] ): SafeHtml { - const key = Symbol.for('e2ed:SafeHtml key'); + const key = Symbol.for('e2ed:SafeHtml:key'); const parts: string[] = []; for (let index = 0; index < values.length; index += 1) { @@ -50,7 +50,7 @@ export function sanitizeHtml( stringParts: readonly string[], ...values: readonly unknown[] ): SafeHtml { - const key = Symbol.for('e2ed:SafeHtml key'); + const key = Symbol.for('e2ed:SafeHtml:key'); const sanitizeValue = (value: unknown): string => String(value) diff --git a/src/utils/requestHooks/RequestHookToWaitForEvents.ts b/src/utils/requestHooks/RequestHookToWaitForEvents.ts index 7278438f..d672253b 100644 --- a/src/utils/requestHooks/RequestHookToWaitForEvents.ts +++ b/src/utils/requestHooks/RequestHookToWaitForEvents.ts @@ -6,6 +6,7 @@ import { } from '../../constants/internal'; import {assertValueIsDefined} from '../asserts'; +import {setReadonlyProperty} from '../setReadonlyProperty'; import {addNotCompleteRequest, completeRequest, processEventsPredicates} from '../waitForEvents'; import {getRequestFromRequestOptions} from './getRequestFromRequestOptions'; @@ -13,6 +14,7 @@ import {getResponseFromResponseEvent} from './getResponseFromResponseEvent'; import {RequestHookWithEvents} from './RequestHookWithEvents'; import type { + Request, RequestHookConfigureResponseEvent, RequestHookContextId, RequestHookRequestEvent, @@ -56,21 +58,27 @@ export class RequestHookToWaitForEvents extends RequestHookWithEvents { */ override async onResponse(event: RequestHookResponseEvent): Promise