@glubean/sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/configure.d.ts +141 -0
- package/dist/configure.d.ts.map +1 -0
- package/dist/configure.js +535 -0
- package/dist/configure.js.map +1 -0
- package/dist/data.d.ts +232 -0
- package/dist/data.d.ts.map +1 -0
- package/dist/data.js +543 -0
- package/dist/data.js.map +1 -0
- package/dist/expect.d.ts +511 -0
- package/dist/expect.d.ts.map +1 -0
- package/dist/expect.js +763 -0
- package/dist/expect.js.map +1 -0
- package/dist/index.d.ts +718 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1015 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +39 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +52 -0
- package/dist/internal.js.map +1 -0
- package/dist/plugin.d.ts +56 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +57 -0
- package/dist/plugin.js.map +1 -0
- package/dist/types.d.ts +1971 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +54 -0
- package/dist/types.js.map +1 -0
- package/package.json +40 -0
package/dist/expect.d.ts
ADDED
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fluent assertion API for Glubean tests.
|
|
3
|
+
*
|
|
4
|
+
* Inspired by Jest/Vitest `expect()` but designed for API testing:
|
|
5
|
+
* - **Soft-by-default**: Failed assertions emit events but do NOT throw.
|
|
6
|
+
* All assertions run and all failures are collected.
|
|
7
|
+
* - **`.orFail()` guard**: Opt-in hard failure for when subsequent code
|
|
8
|
+
* depends on the assertion passing.
|
|
9
|
+
* - **`.not` negation**: Negate any assertion via a getter.
|
|
10
|
+
*
|
|
11
|
+
* The class is framework-agnostic — it accepts an `emitter` callback
|
|
12
|
+
* that routes assertion results into the runner's event pipeline.
|
|
13
|
+
*
|
|
14
|
+
* @module
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* The result emitted for every assertion.
|
|
18
|
+
* This is the payload passed to the emitter callback.
|
|
19
|
+
*/
|
|
20
|
+
export interface AssertionEmission {
|
|
21
|
+
passed: boolean;
|
|
22
|
+
message: string;
|
|
23
|
+
actual?: unknown;
|
|
24
|
+
expected?: unknown;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Callback that routes an assertion result into the runner's event system.
|
|
28
|
+
* In the harness this maps to `ctx.assert(result)`.
|
|
29
|
+
*/
|
|
30
|
+
export type AssertEmitter = (result: AssertionEmission) => void;
|
|
31
|
+
/**
|
|
32
|
+
* Result returned by a custom matcher function.
|
|
33
|
+
* The SDK handles `.not` negation and `.orFail()` automatically based on `passed`.
|
|
34
|
+
*/
|
|
35
|
+
export interface MatcherResult {
|
|
36
|
+
/** Whether the assertion passed. */
|
|
37
|
+
passed: boolean;
|
|
38
|
+
/** Human-readable message describing the assertion (used in reports). */
|
|
39
|
+
message: string;
|
|
40
|
+
/** The actual value (for assertion reports). */
|
|
41
|
+
actual?: unknown;
|
|
42
|
+
/** The expected value (for assertion reports). */
|
|
43
|
+
expected?: unknown;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A custom matcher function for `Expectation.extend()`.
|
|
47
|
+
* Receives the actual value and any extra arguments passed by the user.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* const toBeEven: MatcherFn = (actual) => ({
|
|
52
|
+
* passed: typeof actual === "number" && actual % 2 === 0,
|
|
53
|
+
* message: `to be even`,
|
|
54
|
+
* actual,
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export type MatcherFn = (actual: unknown, ...args: unknown[]) => MatcherResult;
|
|
59
|
+
/**
|
|
60
|
+
* Interface for user-defined custom assertion matchers.
|
|
61
|
+
*
|
|
62
|
+
* Augment this interface via TypeScript **declaration merging** to get
|
|
63
|
+
* type-safe access to matchers registered with `Expectation.extend()`.
|
|
64
|
+
* The SDK merges `CustomMatchers` into the `Expectation` class type, so
|
|
65
|
+
* custom matchers automatically appear on every `ctx.expect()` call.
|
|
66
|
+
*
|
|
67
|
+
* **Important**: Call `Expectation.extend(matchers)` at the top of your test
|
|
68
|
+
* file to register the runtime implementation. The declaration merging below
|
|
69
|
+
* only provides type information.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* // 1. Declare the types (in your test file or a shared .d.ts):
|
|
74
|
+
* declare module "@glubean/sdk/expect" {
|
|
75
|
+
* interface CustomMatchers<T> {
|
|
76
|
+
* toBeEven(): Expectation<T>;
|
|
77
|
+
* toBeWithinRange(min: number, max: number): Expectation<T>;
|
|
78
|
+
* }
|
|
79
|
+
* }
|
|
80
|
+
*
|
|
81
|
+
* // 2. Register the runtime implementations:
|
|
82
|
+
* import { Expectation } from "@glubean/sdk/expect";
|
|
83
|
+
*
|
|
84
|
+
* Expectation.extend({
|
|
85
|
+
* toBeEven: (actual) => ({
|
|
86
|
+
* passed: typeof actual === "number" && actual % 2 === 0,
|
|
87
|
+
* message: "to be even",
|
|
88
|
+
* actual,
|
|
89
|
+
* }),
|
|
90
|
+
* toBeWithinRange: (actual, min, max) => ({
|
|
91
|
+
* passed: typeof actual === "number"
|
|
92
|
+
* && actual >= (min as number) && actual <= (max as number),
|
|
93
|
+
* message: `to be within [${min}, ${max}]`,
|
|
94
|
+
* actual,
|
|
95
|
+
* expected: `[${min}, ${max}]`,
|
|
96
|
+
* }),
|
|
97
|
+
* });
|
|
98
|
+
*
|
|
99
|
+
* // 3. Use — fully typed, no `as any` needed:
|
|
100
|
+
* ctx.expect(4).toBeEven(); // ✅ typed
|
|
101
|
+
* ctx.expect(5).not.toBeEven(); // ✅ negation
|
|
102
|
+
* ctx.expect(50).toBeWithinRange(0, 100).orFail(); // ✅ chaining
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* @template T The type of the actual value being asserted on
|
|
106
|
+
*/
|
|
107
|
+
export interface CustomMatchers<T = unknown> {
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Produce a short, human-readable representation of a value for error messages.
|
|
111
|
+
* Truncates long output to keep assertion messages scannable.
|
|
112
|
+
*/
|
|
113
|
+
export declare function inspect(value: unknown, maxLen?: number): string;
|
|
114
|
+
/**
|
|
115
|
+
* Deep equality check.
|
|
116
|
+
* Handles primitives, arrays, plain objects, Date, RegExp, Map, Set, null, undefined.
|
|
117
|
+
* Safely handles circular references via a seen-pairs set.
|
|
118
|
+
*/
|
|
119
|
+
export declare function deepEqual(a: unknown, b: unknown, seen?: Set<object>): boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Error thrown by `.orFail()` when the preceding assertion failed.
|
|
122
|
+
* Caught by the harness as a hard failure.
|
|
123
|
+
*/
|
|
124
|
+
export declare class ExpectFailError extends Error {
|
|
125
|
+
constructor(message: string);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Merges `CustomMatchers` into the `Expectation` class type.
|
|
129
|
+
* This enables declaration merging: when users augment `CustomMatchers<T>`,
|
|
130
|
+
* the additional methods automatically appear on `Expectation<T>` instances.
|
|
131
|
+
*/
|
|
132
|
+
export interface Expectation<T> extends CustomMatchers<T> {
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Fluent assertion object returned by `ctx.expect(actual)`.
|
|
136
|
+
*
|
|
137
|
+
* Every terminal method (e.g. `toBe`, `toContain`) emits an assertion event
|
|
138
|
+
* and returns `this` for optional chaining with `.orFail()`.
|
|
139
|
+
*
|
|
140
|
+
* **Soft-by-default**: failed assertions are recorded but execution continues.
|
|
141
|
+
*
|
|
142
|
+
* **Custom matchers**: Use `Expectation.extend()` to add domain-specific
|
|
143
|
+
* assertions. Combine with `CustomMatchers` declaration merging for full
|
|
144
|
+
* type safety — see {@link CustomMatchers} for details.
|
|
145
|
+
*
|
|
146
|
+
* **Assertion messages**: Every matcher accepts an optional `message` string as
|
|
147
|
+
* its last argument. When provided, it is prepended to the auto-generated
|
|
148
|
+
* message: `"GET /users status: expected 401 to be 200"`. This makes failures
|
|
149
|
+
* far more actionable in Trace Viewer, CI logs, and MCP tool output.
|
|
150
|
+
*
|
|
151
|
+
* @example Basic assertions
|
|
152
|
+
* ```ts
|
|
153
|
+
* ctx.expect(res.status).toBe(200);
|
|
154
|
+
* ctx.expect(body.users).toHaveLength(3);
|
|
155
|
+
* ctx.expect(body).toMatchObject({ success: true });
|
|
156
|
+
* ```
|
|
157
|
+
*
|
|
158
|
+
* @example With descriptive messages (recommended)
|
|
159
|
+
* ```ts
|
|
160
|
+
* ctx.expect(res.status).toBe(200, "GET /users status");
|
|
161
|
+
* ctx.expect(body.users).toHaveLength(3, "user list count");
|
|
162
|
+
* ctx.expect(res).toHaveHeader("content-type", /json/, "response content type");
|
|
163
|
+
* ```
|
|
164
|
+
*
|
|
165
|
+
* @example Guard + message
|
|
166
|
+
* ```ts
|
|
167
|
+
* ctx.expect(res.status).toBe(200, "POST /orders").orFail();
|
|
168
|
+
* const body = await res.json(); // safe — status was 200
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
export declare class Expectation<T> {
|
|
172
|
+
/**
|
|
173
|
+
* The actual value being asserted on.
|
|
174
|
+
* `protected` (not `#private`) so that `Expectation.extend()` prototype
|
|
175
|
+
* patching can access it at runtime.
|
|
176
|
+
*/
|
|
177
|
+
protected _actual: T;
|
|
178
|
+
private _negated;
|
|
179
|
+
private _emit;
|
|
180
|
+
/** Tracks whether the last assertion in this chain passed. */
|
|
181
|
+
private _lastPassed;
|
|
182
|
+
private _lastMessage;
|
|
183
|
+
constructor(actual: T, emit: AssertEmitter, negated?: boolean);
|
|
184
|
+
/**
|
|
185
|
+
* Negate the next assertion.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ctx.expect(body.banned).not.toBe(true);
|
|
189
|
+
* ctx.expect(body.roles).not.toContain("superadmin");
|
|
190
|
+
*/
|
|
191
|
+
get not(): Expectation<T>;
|
|
192
|
+
/**
|
|
193
|
+
* If the preceding assertion failed, throw immediately to abort the test.
|
|
194
|
+
* Use this for "guard" assertions where subsequent code depends on the value.
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ctx.expect(res.status).toBe(200).orFail();
|
|
198
|
+
* const body = await res.json(); // safe — status was 200
|
|
199
|
+
*/
|
|
200
|
+
orFail(): this;
|
|
201
|
+
/**
|
|
202
|
+
* Register custom assertion matchers on the `Expectation` prototype.
|
|
203
|
+
*
|
|
204
|
+
* Each matcher is a pure function that receives the actual value and any
|
|
205
|
+
* extra arguments, and returns a `MatcherResult`. The SDK automatically
|
|
206
|
+
* handles `.not` negation and `.orFail()` chaining.
|
|
207
|
+
*
|
|
208
|
+
* **Isolation**: Each test file runs in its own Deno subprocess, so
|
|
209
|
+
* prototype mutations from `Expectation.extend()` do not leak between files.
|
|
210
|
+
*
|
|
211
|
+
* **Type safety**: To get full TypeScript support for custom matchers,
|
|
212
|
+
* augment the {@link CustomMatchers} interface via declaration merging.
|
|
213
|
+
* See {@link CustomMatchers} for a complete example.
|
|
214
|
+
*
|
|
215
|
+
* @param matchers Record of matcher name → matcher function
|
|
216
|
+
* @throws If a matcher name conflicts with an existing method
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```ts
|
|
220
|
+
* // Step 1: Declare types (in your test file or shared .d.ts)
|
|
221
|
+
* declare module "@glubean/sdk/expect" {
|
|
222
|
+
* interface CustomMatchers<T> {
|
|
223
|
+
* toBeEven(): Expectation<T>;
|
|
224
|
+
* toBeWithinRange(min: number, max: number): Expectation<T>;
|
|
225
|
+
* }
|
|
226
|
+
* }
|
|
227
|
+
*
|
|
228
|
+
* // Step 2: Register runtime implementations
|
|
229
|
+
* import { Expectation } from "@glubean/sdk/expect";
|
|
230
|
+
*
|
|
231
|
+
* Expectation.extend({
|
|
232
|
+
* toBeEven: (actual) => ({
|
|
233
|
+
* passed: typeof actual === "number" && actual % 2 === 0,
|
|
234
|
+
* message: "to be even",
|
|
235
|
+
* actual,
|
|
236
|
+
* }),
|
|
237
|
+
* toBeWithinRange: (actual, min, max) => ({
|
|
238
|
+
* passed: typeof actual === "number" && actual >= (min as number) && actual <= (max as number),
|
|
239
|
+
* message: `to be within [${min}, ${max}]`,
|
|
240
|
+
* actual,
|
|
241
|
+
* expected: `[${min}, ${max}]`,
|
|
242
|
+
* }),
|
|
243
|
+
* });
|
|
244
|
+
*
|
|
245
|
+
* // Step 3: Use — fully typed
|
|
246
|
+
* ctx.expect(count).toBeEven();
|
|
247
|
+
* ctx.expect(count).not.toBeEven();
|
|
248
|
+
* ctx.expect(score).toBeWithinRange(0, 100).orFail();
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
static extend(matchers: Record<string, MatcherFn>): void;
|
|
252
|
+
/**
|
|
253
|
+
* Emit an assertion result.
|
|
254
|
+
* `protected` so that `Expectation.extend()` prototype patching can call it.
|
|
255
|
+
*
|
|
256
|
+
* @param label Optional human-readable context prepended to the message
|
|
257
|
+
* (e.g. `"GET /users status"` → `"GET /users status: expected 401 to be 200"`).
|
|
258
|
+
*/
|
|
259
|
+
protected _report(rawPassed: boolean, message: string, actual?: unknown, expected?: unknown, label?: string): this;
|
|
260
|
+
/**
|
|
261
|
+
* Strict equality (`Object.is`).
|
|
262
|
+
*
|
|
263
|
+
* @param expected The value to compare against
|
|
264
|
+
* @param message Optional context prepended to the assertion message
|
|
265
|
+
*
|
|
266
|
+
* @example ctx.expect(res.status).toBe(200, "GET /users status");
|
|
267
|
+
*/
|
|
268
|
+
toBe(expected: T, message?: string): this;
|
|
269
|
+
/**
|
|
270
|
+
* Deep equality.
|
|
271
|
+
*
|
|
272
|
+
* @param expected The value to compare against
|
|
273
|
+
* @param message Optional context prepended to the assertion message
|
|
274
|
+
*
|
|
275
|
+
* @example ctx.expect(body).toEqual({ id: 1, name: "Alice" }, "response body");
|
|
276
|
+
*/
|
|
277
|
+
toEqual(expected: T, message?: string): this;
|
|
278
|
+
/**
|
|
279
|
+
* Check the runtime type via `typeof`.
|
|
280
|
+
*
|
|
281
|
+
* @param expected The expected type string
|
|
282
|
+
* @param message Optional context prepended to the assertion message
|
|
283
|
+
*
|
|
284
|
+
* @example ctx.expect(body.name).toBeType("string", "user name type");
|
|
285
|
+
*/
|
|
286
|
+
toBeType(expected: "string" | "number" | "boolean" | "object" | "undefined" | "function" | "bigint" | "symbol", message?: string): this;
|
|
287
|
+
/**
|
|
288
|
+
* Check that the value is truthy.
|
|
289
|
+
*
|
|
290
|
+
* @param message Optional context prepended to the assertion message
|
|
291
|
+
*
|
|
292
|
+
* @example ctx.expect(body.active).toBeTruthy("user active flag");
|
|
293
|
+
*/
|
|
294
|
+
toBeTruthy(message?: string): this;
|
|
295
|
+
/**
|
|
296
|
+
* Check that the value is falsy.
|
|
297
|
+
*
|
|
298
|
+
* @param message Optional context prepended to the assertion message
|
|
299
|
+
*
|
|
300
|
+
* @example ctx.expect(body.deleted).toBeFalsy("user should not be deleted");
|
|
301
|
+
*/
|
|
302
|
+
toBeFalsy(message?: string): this;
|
|
303
|
+
/**
|
|
304
|
+
* Check that the value is `null`.
|
|
305
|
+
*
|
|
306
|
+
* @param message Optional context prepended to the assertion message
|
|
307
|
+
*
|
|
308
|
+
* @example ctx.expect(body.avatar).toBeNull("deleted user avatar");
|
|
309
|
+
*/
|
|
310
|
+
toBeNull(message?: string): this;
|
|
311
|
+
/**
|
|
312
|
+
* Check that the value is `undefined`.
|
|
313
|
+
*
|
|
314
|
+
* @param message Optional context prepended to the assertion message
|
|
315
|
+
*
|
|
316
|
+
* @example ctx.expect(body.nickname).toBeUndefined();
|
|
317
|
+
*/
|
|
318
|
+
toBeUndefined(message?: string): this;
|
|
319
|
+
/**
|
|
320
|
+
* Check that the value is not `undefined`.
|
|
321
|
+
*
|
|
322
|
+
* @param message Optional context prepended to the assertion message
|
|
323
|
+
*
|
|
324
|
+
* @example ctx.expect(body.id).toBeDefined("response should include id");
|
|
325
|
+
*/
|
|
326
|
+
toBeDefined(message?: string): this;
|
|
327
|
+
/**
|
|
328
|
+
* Check that the value is greater than `n`.
|
|
329
|
+
*
|
|
330
|
+
* @param n The lower bound (exclusive)
|
|
331
|
+
* @param message Optional context prepended to the assertion message
|
|
332
|
+
*
|
|
333
|
+
* @example ctx.expect(body.age).toBeGreaterThan(0, "user age");
|
|
334
|
+
*/
|
|
335
|
+
toBeGreaterThan(n: number, message?: string): this;
|
|
336
|
+
/**
|
|
337
|
+
* Check that the value is greater than or equal to `n`.
|
|
338
|
+
*
|
|
339
|
+
* @param n The lower bound (inclusive)
|
|
340
|
+
* @param message Optional context prepended to the assertion message
|
|
341
|
+
*
|
|
342
|
+
* @example ctx.expect(body.items.length).toBeGreaterThanOrEqual(1, "result count");
|
|
343
|
+
*/
|
|
344
|
+
toBeGreaterThanOrEqual(n: number, message?: string): this;
|
|
345
|
+
/**
|
|
346
|
+
* Check that the value is less than `n`.
|
|
347
|
+
*
|
|
348
|
+
* @param n The upper bound (exclusive)
|
|
349
|
+
* @param message Optional context prepended to the assertion message
|
|
350
|
+
*
|
|
351
|
+
* @example ctx.expect(latency).toBeLessThan(500, "response latency ms");
|
|
352
|
+
*/
|
|
353
|
+
toBeLessThan(n: number, message?: string): this;
|
|
354
|
+
/**
|
|
355
|
+
* Check that the value is less than or equal to `n`.
|
|
356
|
+
*
|
|
357
|
+
* @param n The upper bound (inclusive)
|
|
358
|
+
* @param message Optional context prepended to the assertion message
|
|
359
|
+
*
|
|
360
|
+
* @example ctx.expect(res.status).toBeLessThanOrEqual(299, "GET /users status range");
|
|
361
|
+
*/
|
|
362
|
+
toBeLessThanOrEqual(n: number, message?: string): this;
|
|
363
|
+
/**
|
|
364
|
+
* Check that the value is within `[min, max]` (inclusive).
|
|
365
|
+
*
|
|
366
|
+
* @param min Lower bound (inclusive)
|
|
367
|
+
* @param max Upper bound (inclusive)
|
|
368
|
+
* @param message Optional context prepended to the assertion message
|
|
369
|
+
*
|
|
370
|
+
* @example ctx.expect(body.score).toBeWithin(0, 100, "user score range");
|
|
371
|
+
*/
|
|
372
|
+
toBeWithin(min: number, max: number, message?: string): this;
|
|
373
|
+
/**
|
|
374
|
+
* Check that the value has the expected `length`.
|
|
375
|
+
*
|
|
376
|
+
* @param expected The expected length
|
|
377
|
+
* @param message Optional context prepended to the assertion message
|
|
378
|
+
*
|
|
379
|
+
* @example ctx.expect(body.users).toHaveLength(3, "user list count");
|
|
380
|
+
*/
|
|
381
|
+
toHaveLength(expected: number, message?: string): this;
|
|
382
|
+
/**
|
|
383
|
+
* Check that an array or string contains the given item/substring.
|
|
384
|
+
*
|
|
385
|
+
* @param item The item or substring to search for
|
|
386
|
+
* @param message Optional context prepended to the assertion message
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* ctx.expect(body.roles).toContain("admin", "user roles");
|
|
390
|
+
* ctx.expect(body.name).toContain("Ali");
|
|
391
|
+
*/
|
|
392
|
+
toContain(item: unknown, message?: string): this;
|
|
393
|
+
/**
|
|
394
|
+
* Check that a string matches a regex or includes a substring.
|
|
395
|
+
*
|
|
396
|
+
* @param pattern Regex or substring to match
|
|
397
|
+
* @param message Optional context prepended to the assertion message
|
|
398
|
+
*
|
|
399
|
+
* @example
|
|
400
|
+
* ctx.expect(body.email).toMatch(/@example\.com$/, "email domain");
|
|
401
|
+
* ctx.expect(body.name).toMatch("Alice");
|
|
402
|
+
*/
|
|
403
|
+
toMatch(pattern: RegExp | string, message?: string): this;
|
|
404
|
+
/**
|
|
405
|
+
* Check that a string starts with the given prefix.
|
|
406
|
+
*
|
|
407
|
+
* @param prefix The expected prefix
|
|
408
|
+
* @param message Optional context prepended to the assertion message
|
|
409
|
+
*
|
|
410
|
+
* @example
|
|
411
|
+
* ctx.expect(body.id).toStartWith("usr_", "user id prefix");
|
|
412
|
+
* ctx.expect(url).toStartWith("https://");
|
|
413
|
+
*/
|
|
414
|
+
toStartWith(prefix: string, message?: string): this;
|
|
415
|
+
/**
|
|
416
|
+
* Check that a string ends with the given suffix.
|
|
417
|
+
*
|
|
418
|
+
* @param suffix The expected suffix
|
|
419
|
+
* @param message Optional context prepended to the assertion message
|
|
420
|
+
*
|
|
421
|
+
* @example
|
|
422
|
+
* ctx.expect(body.email).toEndWith("@example.com", "email format");
|
|
423
|
+
* ctx.expect(body.filename).toEndWith(".json");
|
|
424
|
+
*/
|
|
425
|
+
toEndWith(suffix: string, message?: string): this;
|
|
426
|
+
/**
|
|
427
|
+
* Partial deep match — every key in `subset` must exist and match in the actual value.
|
|
428
|
+
*
|
|
429
|
+
* @param subset The expected subset of properties
|
|
430
|
+
* @param message Optional context prepended to the assertion message
|
|
431
|
+
*
|
|
432
|
+
* @example ctx.expect(body).toMatchObject({ success: true }, "create user response");
|
|
433
|
+
*/
|
|
434
|
+
toMatchObject(subset: Record<string, unknown>, message?: string): this;
|
|
435
|
+
/**
|
|
436
|
+
* Check that the value has a property at the given path.
|
|
437
|
+
* When `value` is provided, also checks property value equality.
|
|
438
|
+
*
|
|
439
|
+
* @param path Dot-separated property path (e.g. `"meta.created"`)
|
|
440
|
+
* @param value Expected value at the path (omit to check existence only)
|
|
441
|
+
* @param message Optional context prepended to the assertion message
|
|
442
|
+
*
|
|
443
|
+
* @example Existence check
|
|
444
|
+
* ```ts
|
|
445
|
+
* ctx.expect(body).toHaveProperty("id");
|
|
446
|
+
* ```
|
|
447
|
+
*
|
|
448
|
+
* @example Value check with message
|
|
449
|
+
* ```ts
|
|
450
|
+
* ctx.expect(body).toHaveProperty("status", "active", "user status");
|
|
451
|
+
* ```
|
|
452
|
+
*/
|
|
453
|
+
toHaveProperty(path: string, value?: unknown, message?: string): this;
|
|
454
|
+
/**
|
|
455
|
+
* Check that the value has all of the given property keys.
|
|
456
|
+
* Reports all missing keys in a single assertion message.
|
|
457
|
+
*
|
|
458
|
+
* @param keys Array of property paths to check
|
|
459
|
+
* @param message Optional context prepended to the assertion message
|
|
460
|
+
*
|
|
461
|
+
* @example
|
|
462
|
+
* ctx.expect(body).toHaveProperties(["id", "name", "email"], "user fields");
|
|
463
|
+
*/
|
|
464
|
+
toHaveProperties(keys: string[], message?: string): this;
|
|
465
|
+
/**
|
|
466
|
+
* Custom predicate assertion.
|
|
467
|
+
*
|
|
468
|
+
* @param predicate Function that returns `true` if the assertion passes
|
|
469
|
+
* @param message Optional context prepended to the assertion message
|
|
470
|
+
*
|
|
471
|
+
* @example ctx.expect(body).toSatisfy((b) => b.items.length > 0, "response should have items");
|
|
472
|
+
*/
|
|
473
|
+
toSatisfy(predicate: (actual: T) => boolean, message?: string): this;
|
|
474
|
+
/**
|
|
475
|
+
* Assert on the `status` property (typically a `Response` object).
|
|
476
|
+
*
|
|
477
|
+
* @param code Expected HTTP status code
|
|
478
|
+
* @param message Optional context prepended to the assertion message
|
|
479
|
+
*
|
|
480
|
+
* @example ctx.expect(res).toHaveStatus(200, "GET /users");
|
|
481
|
+
*/
|
|
482
|
+
toHaveStatus(code: number, message?: string): this;
|
|
483
|
+
/**
|
|
484
|
+
* Assert that a Response-like object has a JSON body matching the given subset
|
|
485
|
+
* (partial deep match, like `toMatchObject`).
|
|
486
|
+
*
|
|
487
|
+
* This method is **async** because it calls `.json()` on the response.
|
|
488
|
+
*
|
|
489
|
+
* @param subset Expected subset of properties in the JSON body
|
|
490
|
+
* @param message Optional context prepended to the assertion message
|
|
491
|
+
*
|
|
492
|
+
* @example
|
|
493
|
+
* await ctx.expect(res).toHaveJsonBody({ success: true }, "create order response");
|
|
494
|
+
* (await ctx.expect(res).toHaveJsonBody({ ok: true }, "health check")).orFail();
|
|
495
|
+
*/
|
|
496
|
+
toHaveJsonBody(subset: Record<string, unknown>, message?: string): Promise<this>;
|
|
497
|
+
/**
|
|
498
|
+
* Assert that a `Response` or headers-like object has a specific header.
|
|
499
|
+
* Optionally check the header value against a string or regex.
|
|
500
|
+
*
|
|
501
|
+
* @param name Header name (case-insensitive for `Headers` objects)
|
|
502
|
+
* @param value Optional expected value or pattern
|
|
503
|
+
* @param message Optional context prepended to the assertion message
|
|
504
|
+
*
|
|
505
|
+
* @example
|
|
506
|
+
* ctx.expect(res).toHaveHeader("content-type", /json/, "response content type");
|
|
507
|
+
* ctx.expect(res).toHaveHeader("x-request-id");
|
|
508
|
+
*/
|
|
509
|
+
toHaveHeader(name: string, value?: string | RegExp, message?: string): this;
|
|
510
|
+
}
|
|
511
|
+
//# sourceMappingURL=expect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../src/expect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAMH;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,iBAAiB,KAAK,IAAI,CAAC;AAEhE;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,oCAAoC;IACpC,MAAM,EAAE,OAAO,CAAC;IAChB,yEAAyE;IACzE,OAAO,EAAE,MAAM,CAAC;IAChB,gDAAgD;IAChD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,aAAa,CAAC;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AAEH,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,OAAO;CAAI;AAM/C;;;GAGG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,SAAK,GAAG,MAA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