Skip to content

Commit adba5aa

Browse files
committed
2 parents 6025796 + 7f65084 commit adba5aa

File tree

5 files changed

+581
-1
lines changed

5 files changed

+581
-1
lines changed

types/supertest/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import superagent = require("superagent");
22
import stAgent = require("./lib/agent");
33
import STest = require("./lib/test");
4+
import cookies = require("./lib/cookies");
45
import { AgentOptions as STAgentOptions, App } from "./types";
56

67
declare const supertest: supertest.SuperTestStatic;
@@ -28,10 +29,13 @@ declare namespace supertest {
2829

2930
type SuperAgentTest = SuperTest<Test>;
3031

32+
type CustomAssertionCookie = cookies.CustomAssertionCookie;
33+
3134
interface SuperTestStatic {
3235
(app: App, options?: STAgentOptions): stAgent;
3336
Test: typeof STest;
3437
agent: typeof stAgent & ((app?: App, options?: STAgentOptions) => InstanceType<typeof stAgent>);
38+
cookies: typeof cookies;
3539
}
3640
}
3741

types/supertest/lib/cookies.d.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
declare const expectCookies: expectCookies.ExpectCookiesStatic;
2+
3+
declare namespace expectCookies {
4+
interface Assertion {
5+
set(expects: SetMatcher | ReadonlyArray<SetMatcher>, assert?: boolean): this;
6+
7+
reset(expects: ResetMatcher | ReadonlyArray<ResetMatcher>, assert?: boolean): this;
8+
9+
"new"(expects: ResetMatcher | ReadonlyArray<ResetMatcher>, assert?: boolean): this;
10+
11+
renew(expects: RenewMatcher | ReadonlyArray<RenewMatcher>, assert?: boolean): this;
12+
13+
contain(expects: ContainMatcher | ReadonlyArray<ContainMatcher>, assert?: boolean): this;
14+
15+
not<M extends keyof Omit<Assertion, "not">>(
16+
method: M,
17+
expects: AssertionMatchers[M] | ReadonlyArray<AssertionMatchers[M]>,
18+
): this;
19+
}
20+
21+
type CustomAssertion = (
22+
req: { cookies: CustomAssertionCookie[] },
23+
res: { cookies: CustomAssertionCookie[] },
24+
) => boolean;
25+
26+
interface CustomAssertionCookie {
27+
name: string;
28+
value: string;
29+
options?: Record<string, string | boolean>;
30+
}
31+
32+
interface AssertionMatchers {
33+
readonly set: SetMatcher;
34+
readonly reset: ResetMatcher;
35+
readonly new: NewMatcher;
36+
readonly renew: RenewMatcher;
37+
readonly contain: ContainMatcher;
38+
}
39+
40+
interface SetMatcher {
41+
readonly name: string;
42+
readonly options?: Record<string, string | boolean>;
43+
}
44+
45+
interface ResetMatcher {
46+
readonly name: string;
47+
}
48+
49+
type NewMatcher = ResetMatcher;
50+
51+
interface RenewMatcher {
52+
readonly name: string;
53+
54+
readonly options:
55+
| { "max-age": number; expires?: never }
56+
| { expires: Date; "max-age"?: never };
57+
}
58+
59+
interface ContainMatcher {
60+
readonly name: string;
61+
62+
readonly value: string | boolean;
63+
64+
readonly options?: {
65+
readonly domain?: string;
66+
readonly path?: string;
67+
readonly expires?: string; // RFC 6265 sane-cookie-date (e.g. "Fri, 26 Sep 2025 04:26:52 GMT")
68+
readonly secure?: boolean;
69+
readonly httponly?: boolean;
70+
readonly "max-age"?: string;
71+
};
72+
}
73+
74+
interface ExpectCookiesStatic extends Assertion {
75+
(
76+
secret?: string | ReadonlyArray<string> | null,
77+
asserts?: CustomAssertion | ReadonlyArray<CustomAssertion>,
78+
): Assertion;
79+
}
80+
}
81+
82+
export = expectCookies;

types/supertest/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@types/supertest",
4-
"version": "6.0.9999",
4+
"version": "7.2.9999",
55
"projects": [
66
"https://github.com/visionmedia/supertest"
77
],

0 commit comments

Comments
 (0)