@@ -13,67 +13,72 @@ import type { CollectionFormat, RequestExt, Resolver, ResolverConfig } from "./t
1313import { ValidationError } from "./validation-error.js" ;
1414
1515/**
16- * Class containing all the expectations that can be run on the request.
16+ * Assertions against one incoming request. A mismatch throws {@link ValidationError}
17+ * with expected and actual values; successful assertions return normally.
1718 */
1819export class RequestExpectation {
20+ /** Binds assertions to the supplied request without copying its data. */
1921 public constructor ( private originalRequest : RequestExt ) { }
2022 /**
21- * Expect the raw body of the request to match the given string .
22- * @param rawBody Raw request body .
23- * @throws {ValidationError } if there is an error .
23+ * Requires strict equality of raw strings or Buffer bytes, without converting between them .
24+ * An undefined expectation requires an empty raw payload .
25+ * @throws {ValidationError } when the payload differs .
2426 */
2527 public rawBodyEquals ( expectedRawBody : string | Buffer | undefined ) : void {
2628 validateRawBodyEquals ( this . originalRequest , expectedRawBody ) ;
2729 }
2830
2931 /**
30- * Expect the body of the request to match the given object .
31- * @param rawBody Raw request body .
32- * @throws {ValidationError } if there is an error .
32+ * Compares the parsed body using { @link matchValues}, including nested value matchers .
33+ * A null or undefined expectation instead requires an empty raw payload .
34+ * @throws {ValidationError } when the payload differs .
3335 */
3436 public bodyEquals ( expectedRawBody : unknown | undefined ) : void {
3537 validateBodyEquals ( this . originalRequest , expectedRawBody ) ;
3638 }
3739
3840 /**
39- * Expect the coerced body of the request to match the given object.
40- * @param rawBody Raw request body.
41- * @throws {ValidationError } if there is an error.
41+ * JSON-round-trips the actual body and normalizes UTC datetime strings before
42+ * matcher-aware comparison. Removes 3–7 fractional digits and replaces zero offsets
43+ * with `Z`; the expected value is not normalized.
44+ * A null or undefined expectation requires an empty raw payload.
45+ * @throws {ValidationError } when the payload differs.
4246 */
4347 public coercedBodyEquals ( expectedRawBody : unknown | undefined ) : void {
4448 validateCoercedDateBodyEquals ( this . originalRequest , expectedRawBody ) ;
4549 }
4650
4751 /**
48- * Expect the body of the request to be empty.
49- * @throws {ValidationError } if there is an error.
52+ * Requires an empty raw body and rejects a nonempty parsed Buffer.
53+ * Other parsed values do not determine emptiness.
54+ * @throws {ValidationError } when a body is present.
5055 */
5156 public bodyEmpty ( ) : void {
5257 validateBodyEmpty ( this . originalRequest ) ;
5358 }
5459
5560 /**
56- * Expect the body of the request to be not empty.
61+ * Requires a nonempty raw payload, falling back to the parsed Buffer when rawBody is empty.
5762 * @throws {ValidationError } if there is an error.
5863 */
5964 public bodyNotEmpty ( ) : void {
6065 validateBodyNotEmpty ( this . originalRequest ) ;
6166 }
6267
6368 /**
64- * Expect the header of the request contains the expected key/value pair
65- * @param headerName Key expected in header
66- * @param expectedValue Values expected in header
67- * @throws {ValidationError } if there is an error.
69+ * Requires the parsed header value to equal the expected string exactly.
70+ * Use a lowercase header name; other headers are not checked.
71+ * @throws {ValidationError } when the header is absent or differs.
6872 */
6973 public containsHeader ( headerName : string , expectedValue : string ) : void {
7074 validateHeader ( this . originalRequest , headerName , expectedValue ) ;
7175 }
7276
7377 /**
74- * Expect the query string of the request contains the expected name/value pair.
75- * @param paramName Name of the query parameter.
76- * @param expectedValue Value expected of the query parameter.
78+ * Requires a query parameter to equal the expected string or encoded collection.
79+ * For arrays, specify `multi` for repeated parameters or a delimiter format;
80+ * array element order is significant. Other query parameters are not checked.
81+ * @throws {ValidationError } when the parameter is absent or differs.
7782 */
7883 public containsQueryParam (
7984 paramName : string ,
@@ -84,9 +89,10 @@ export class RequestExpectation {
8489 }
8590
8691 /**
87- * Check if two requests are equal
88- * @param actual Actual value
89- * @param expected Expected value
92+ * Compares arbitrary values using {@link matchValues}, accepting matchers in the
93+ * expected tree. The failure message includes the first mismatching value's path.
94+ * @param message Prefix for the mismatch detail.
95+ * @throws {ValidationError } when the values do not match.
9096 */
9197 public deepEqual ( actual : unknown , expected : unknown , message = "Values not deep equal" ) : void {
9298 const result = matchValues ( actual , expected ) ;
@@ -96,12 +102,11 @@ export class RequestExpectation {
96102 }
97103
98104 /**
99- * Expect the body of the request to be semantically equivalent to the provided XML.
100- * Accepts a plain string or a Resolver (e.g. from `xml\`...\``).
101- * When a Resolver with matchers is provided, matcher-aware comparison is used.
102- * The XML declaration prefix will automatically be added.
103- * @param expectedBody expected XML body as a string or Resolver.
104- * @param config resolver config (required when expectedBody is a Resolver).
105+ * Compares parsed XML using string-valued tag content. Plain strings have an XML declaration
106+ * added; Resolvers supply serialized XML, with template matchers recovered through getMatchers.
107+ * @param expectedBody XML string or Resolver. The xml helper returns a MockBody; for tagged
108+ * XML, narrow its rawContent to a Resolver and pass that, not the body wrapper.
109+ * @param config Context for resolving dynamic values; defaults to an empty base URL.
105110 * @throws {ValidationError } if there is an error.
106111 */
107112 public xmlBodyEquals ( expectedBody : string | Resolver , config ?: ResolverConfig ) : void {
0 commit comments