@thisisagile/easy-test 19.1.3 → 20.0.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/index.d.ts +24 -2
- package/dist/index.js +22 -618
- package/dist/matchers/Check.d.ts +13 -10
- package/dist/matchers/Check.js +42 -0
- package/dist/matchers/Check.js.map +1 -0
- package/dist/matchers/HttpMatchers.d.ts +19 -16
- package/dist/matchers/HttpMatchers.js +32 -0
- package/dist/matchers/HttpMatchers.js.map +1 -0
- package/dist/matchers/Match.d.ts +11 -8
- package/dist/matchers/Match.js +35 -0
- package/dist/matchers/Match.js.map +1 -0
- package/dist/matchers/ResultMatchers.d.ts +10 -7
- package/dist/matchers/ResultMatchers.js +18 -0
- package/dist/matchers/ResultMatchers.js.map +1 -0
- package/dist/matchers/index.d.ts +20 -19
- package/dist/matchers/index.js +20 -0
- package/dist/matchers/toBeArrayOf.d.ts +9 -6
- package/dist/matchers/toBeArrayOf.js +8 -0
- package/dist/matchers/toBeArrayOf.js.map +1 -0
- package/dist/matchers/toBeArrayOfWithLength.d.ts +9 -6
- package/dist/matchers/toBeArrayOfWithLength.js +8 -0
- package/dist/matchers/toBeArrayOfWithLength.js.map +1 -0
- package/dist/matchers/toBeAt.d.ts +8 -5
- package/dist/matchers/toBeAt.js +10 -0
- package/dist/matchers/toBeAt.js.map +1 -0
- package/dist/matchers/toBeExactlyAt.d.ts +8 -5
- package/dist/matchers/toBeExactlyAt.js +15 -0
- package/dist/matchers/toBeExactlyAt.js.map +1 -0
- package/dist/matchers/toBeQueriedWith.d.ts +8 -5
- package/dist/matchers/toBeQueriedWith.js +8 -0
- package/dist/matchers/toBeQueriedWith.js.map +1 -0
- package/dist/matchers/toBeRoutedTo.d.ts +8 -5
- package/dist/matchers/toBeRoutedTo.js +14 -0
- package/dist/matchers/toBeRoutedTo.js.map +1 -0
- package/dist/matchers/toBeValid.d.ts +7 -4
- package/dist/matchers/toBeValid.js +9 -0
- package/dist/matchers/toBeValid.js.map +1 -0
- package/dist/matchers/toFailMatcher.d.ts +13 -10
- package/dist/matchers/toFailMatcher.js +21 -0
- package/dist/matchers/toFailMatcher.js.map +1 -0
- package/dist/matchers/toMatchArray.d.ts +7 -4
- package/dist/matchers/toMatchArray.js +10 -0
- package/dist/matchers/toMatchArray.js.map +1 -0
- package/dist/matchers/toMatchExactJson.d.ts +11 -8
- package/dist/matchers/toMatchExactJson.js +15 -0
- package/dist/matchers/toMatchExactJson.js.map +1 -0
- package/dist/matchers/toMatchException.d.ts +8 -5
- package/dist/matchers/toMatchException.js +9 -0
- package/dist/matchers/toMatchException.js.map +1 -0
- package/dist/matchers/toMatchJson.d.ts +11 -8
- package/dist/matchers/toMatchJson.js +16 -0
- package/dist/matchers/toMatchJson.js.map +1 -0
- package/dist/matchers/toMatchRoute.d.ts +8 -5
- package/dist/matchers/toMatchRoute.js +9 -0
- package/dist/matchers/toMatchRoute.js.map +1 -0
- package/dist/matchers/toMatchText.d.ts +7 -4
- package/dist/matchers/toMatchText.js +9 -0
- package/dist/matchers/toMatchText.js.map +1 -0
- package/dist/matchers/toPassMatcher.d.ts +13 -10
- package/dist/matchers/toPassMatcher.js +21 -0
- package/dist/matchers/toPassMatcher.js.map +1 -0
- package/dist/mock/Fits.d.ts +19 -16
- package/dist/mock/Fits.js +42 -0
- package/dist/mock/Fits.js.map +1 -0
- package/dist/mock/Mocks.d.ts +38 -35
- package/dist/mock/Mocks.js +68 -0
- package/dist/mock/Mocks.js.map +1 -0
- package/dist/mock/index.d.ts +3 -2
- package/dist/mock/index.js +3 -0
- package/dist/utils/Eq.d.ts +6 -3
- package/dist/utils/Eq.js +12 -0
- package/dist/utils/Eq.js.map +1 -0
- package/dist/utils/Req.d.ts +15 -12
- package/dist/utils/Req.js +35 -0
- package/dist/utils/Req.js.map +1 -0
- package/dist/utils/Response.d.ts +22 -19
- package/dist/utils/Response.js +0 -0
- package/dist/utils/Types.d.ts +18 -17
- package/dist/utils/Types.js +7 -0
- package/dist/utils/Types.js.map +1 -0
- package/dist/utils/Utils.d.ts +4 -1
- package/dist/utils/Utils.js +19 -0
- package/dist/utils/Utils.js.map +1 -0
- package/package.json +36 -34
- package/dist/chunk-6EKWTLNQ.mjs +0 -12
- package/dist/chunk-6EKWTLNQ.mjs.map +0 -1
- package/dist/chunk-6FEQASGO.mjs +0 -17
- package/dist/chunk-6FEQASGO.mjs.map +0 -1
- package/dist/chunk-ART72TJA.mjs +0 -25
- package/dist/chunk-ART72TJA.mjs.map +0 -1
- package/dist/chunk-BN2IG45X.mjs +0 -24
- package/dist/chunk-BN2IG45X.mjs.map +0 -1
- package/dist/chunk-BZXBZCMZ.mjs +0 -26
- package/dist/chunk-BZXBZCMZ.mjs.map +0 -1
- package/dist/chunk-CQPHLHB7.mjs +0 -86
- package/dist/chunk-CQPHLHB7.mjs.map +0 -1
- package/dist/chunk-DHDFXV7G.mjs +0 -53
- package/dist/chunk-DHDFXV7G.mjs.map +0 -1
- package/dist/chunk-DMSYYRBM.mjs +0 -59
- package/dist/chunk-DMSYYRBM.mjs.map +0 -1
- package/dist/chunk-EZNTPFD2.mjs +0 -39
- package/dist/chunk-EZNTPFD2.mjs.map +0 -1
- package/dist/chunk-GRYVDJXU.mjs +0 -1
- package/dist/chunk-GRYVDJXU.mjs.map +0 -1
- package/dist/chunk-LN24S2PC.mjs +0 -41
- package/dist/chunk-LN24S2PC.mjs.map +0 -1
- package/dist/chunk-MBQSBGEE.mjs +0 -1
- package/dist/chunk-MBQSBGEE.mjs.map +0 -1
- package/dist/chunk-O475TEG2.mjs +0 -30
- package/dist/chunk-O475TEG2.mjs.map +0 -1
- package/dist/chunk-PPXFT3SX.mjs +0 -14
- package/dist/chunk-PPXFT3SX.mjs.map +0 -1
- package/dist/chunk-QE3TR4BY.mjs +0 -16
- package/dist/chunk-QE3TR4BY.mjs.map +0 -1
- package/dist/chunk-QWLALNJL.mjs +0 -30
- package/dist/chunk-QWLALNJL.mjs.map +0 -1
- package/dist/chunk-RPYWAKYZ.mjs +0 -39
- package/dist/chunk-RPYWAKYZ.mjs.map +0 -1
- package/dist/chunk-SGV4XPW3.mjs +0 -27
- package/dist/chunk-SGV4XPW3.mjs.map +0 -1
- package/dist/chunk-SJR3TRWF.mjs +0 -39
- package/dist/chunk-SJR3TRWF.mjs.map +0 -1
- package/dist/chunk-TUE23FNE.mjs +0 -17
- package/dist/chunk-TUE23FNE.mjs.map +0 -1
- package/dist/chunk-UFDXFCRK.mjs +0 -19
- package/dist/chunk-UFDXFCRK.mjs.map +0 -1
- package/dist/chunk-UOO6EMXQ.mjs +0 -20
- package/dist/chunk-UOO6EMXQ.mjs.map +0 -1
- package/dist/chunk-WAKTWLNU.mjs +0 -32
- package/dist/chunk-WAKTWLNU.mjs.map +0 -1
- package/dist/chunk-YL7PRCYP.mjs +0 -26
- package/dist/chunk-YL7PRCYP.mjs.map +0 -1
- package/dist/chunk-Z4XAP66Q.mjs +0 -44
- package/dist/chunk-Z4XAP66Q.mjs.map +0 -1
- package/dist/chunk-Z6NXMCUL.mjs +0 -17
- package/dist/chunk-Z6NXMCUL.mjs.map +0 -1
- package/dist/chunk-ZBSBLFC7.mjs +0 -20
- package/dist/chunk-ZBSBLFC7.mjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -151
- package/dist/index.mjs.map +0 -1
- package/dist/matchers/Check.mjs +0 -10
- package/dist/matchers/Check.mjs.map +0 -1
- package/dist/matchers/HttpMatchers.mjs +0 -32
- package/dist/matchers/HttpMatchers.mjs.map +0 -1
- package/dist/matchers/Match.mjs +0 -11
- package/dist/matchers/Match.mjs.map +0 -1
- package/dist/matchers/ResultMatchers.mjs +0 -14
- package/dist/matchers/ResultMatchers.mjs.map +0 -1
- package/dist/matchers/index.mjs +0 -133
- package/dist/matchers/index.mjs.map +0 -1
- package/dist/matchers/toBeArrayOf.mjs +0 -10
- package/dist/matchers/toBeArrayOf.mjs.map +0 -1
- package/dist/matchers/toBeArrayOfWithLength.mjs +0 -10
- package/dist/matchers/toBeArrayOfWithLength.mjs.map +0 -1
- package/dist/matchers/toBeAt.mjs +0 -10
- package/dist/matchers/toBeAt.mjs.map +0 -1
- package/dist/matchers/toBeExactlyAt.mjs +0 -10
- package/dist/matchers/toBeExactlyAt.mjs.map +0 -1
- package/dist/matchers/toBeQueriedWith.mjs +0 -10
- package/dist/matchers/toBeQueriedWith.mjs.map +0 -1
- package/dist/matchers/toBeRoutedTo.mjs +0 -15
- package/dist/matchers/toBeRoutedTo.mjs.map +0 -1
- package/dist/matchers/toBeValid.mjs +0 -10
- package/dist/matchers/toBeValid.mjs.map +0 -1
- package/dist/matchers/toFailMatcher.mjs +0 -16
- package/dist/matchers/toFailMatcher.mjs.map +0 -1
- package/dist/matchers/toMatchArray.mjs +0 -9
- package/dist/matchers/toMatchArray.mjs.map +0 -1
- package/dist/matchers/toMatchExactJson.mjs +0 -13
- package/dist/matchers/toMatchExactJson.mjs.map +0 -1
- package/dist/matchers/toMatchException.mjs +0 -10
- package/dist/matchers/toMatchException.mjs.map +0 -1
- package/dist/matchers/toMatchJson.mjs +0 -13
- package/dist/matchers/toMatchJson.mjs.map +0 -1
- package/dist/matchers/toMatchRoute.mjs +0 -10
- package/dist/matchers/toMatchRoute.mjs.map +0 -1
- package/dist/matchers/toMatchText.mjs +0 -10
- package/dist/matchers/toMatchText.mjs.map +0 -1
- package/dist/matchers/toPassMatcher.mjs +0 -16
- package/dist/matchers/toPassMatcher.mjs.map +0 -1
- package/dist/mock/Fits.mjs +0 -15
- package/dist/mock/Fits.mjs.map +0 -1
- package/dist/mock/Mocks.mjs +0 -11
- package/dist/mock/Mocks.mjs.map +0 -1
- package/dist/mock/index.mjs +0 -23
- package/dist/mock/index.mjs.map +0 -1
- package/dist/utils/Eq.mjs +0 -8
- package/dist/utils/Eq.mjs.map +0 -1
- package/dist/utils/Req.mjs +0 -8
- package/dist/utils/Req.mjs.map +0 -1
- package/dist/utils/Response.mjs +0 -1
- package/dist/utils/Response.mjs.map +0 -1
- package/dist/utils/Types.mjs +0 -8
- package/dist/utils/Types.mjs.map +0 -1
- package/dist/utils/Utils.mjs +0 -27
- package/dist/utils/Utils.mjs.map +0 -1
package/dist/matchers/Check.d.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
+
//#region src/matchers/Check.d.ts
|
|
1
2
|
type ToMessage<S> = string | ((s: S[]) => string);
|
|
2
3
|
declare class Check<S> {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
private ctx;
|
|
5
|
+
private readonly received;
|
|
6
|
+
private readonly expected;
|
|
7
|
+
private readonly failed;
|
|
8
|
+
private readonly message;
|
|
9
|
+
constructor(ctx: jest.MatcherContext, received: S, expected: S, failed?: boolean, message?: string);
|
|
10
|
+
print(message: ToMessage<S>): string;
|
|
11
|
+
not(p: (s: S[]) => boolean, message: ToMessage<S>): Check<S>;
|
|
12
|
+
undefined(p: (s: S[]) => any, message: ToMessage<S>): Check<S>;
|
|
13
|
+
else(message?: ToMessage<S>): jest.CustomMatcherResult;
|
|
13
14
|
}
|
|
14
15
|
export declare const check: <S>(ctx: jest.MatcherContext, received: S, expected?: S) => Check<S>;
|
|
15
16
|
export declare const checkDefined: <S>(ctx: jest.MatcherContext, received: S, expected?: S) => Check<S>;
|
|
17
|
+
//#endregion
|
|
16
18
|
export {};
|
|
19
|
+
//# sourceMappingURL=Check.d.ts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { isDefined } from "../utils/Utils.js";
|
|
2
|
+
//#region src/matchers/Check.ts
|
|
3
|
+
var Check = class Check {
|
|
4
|
+
ctx;
|
|
5
|
+
received;
|
|
6
|
+
expected;
|
|
7
|
+
failed;
|
|
8
|
+
message;
|
|
9
|
+
constructor(ctx, received, expected, failed = false, message = "") {
|
|
10
|
+
this.ctx = ctx;
|
|
11
|
+
this.received = received;
|
|
12
|
+
this.expected = expected;
|
|
13
|
+
this.failed = failed;
|
|
14
|
+
this.message = message;
|
|
15
|
+
}
|
|
16
|
+
print(message) {
|
|
17
|
+
return (typeof message === "function" ? message([this.received, this.expected]) : message).replace("{r}", this.ctx.utils.printReceived(this.received)).replace("{e}", this.ctx.utils.printExpected(this.expected)).replace("{diff}", this.ctx.utils.diff(this.received, this.expected) ?? "");
|
|
18
|
+
}
|
|
19
|
+
not(p, message) {
|
|
20
|
+
if (this.failed) return this;
|
|
21
|
+
try {
|
|
22
|
+
return new Check(this.ctx, this.received, this.expected, !p([this.received, this.expected]), this.print(message));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
return new Check(this.ctx, this.received, this.expected, true, e.message);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
undefined(p, message) {
|
|
28
|
+
return this.not(() => isDefined(p([this.received, this.expected])), this.print(message));
|
|
29
|
+
}
|
|
30
|
+
else(message = "Expected {r} not to match with {e}, but it did.") {
|
|
31
|
+
return {
|
|
32
|
+
pass: !this.failed,
|
|
33
|
+
message: () => this.failed ? this.message : this.print(message)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const check = (ctx, received, expected) => new Check(ctx, received, expected);
|
|
38
|
+
const checkDefined = (ctx, received, expected) => new Check(ctx, received, expected).undefined(([r]) => r, "Received array is undefined.").undefined(([, e]) => e, "Expected array is undefined.");
|
|
39
|
+
//#endregion
|
|
40
|
+
export { check, checkDefined };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=Check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Check.js","names":[],"sources":["../../src/matchers/Check.ts"],"sourcesContent":["import { isDefined } from '../utils/Utils';\n\ntype ToMessage<S> = string | ((s: S[]) => string);\n\nclass Check<S> {\n constructor(\n private ctx: jest.MatcherContext,\n private readonly received: S,\n private readonly expected: S,\n private readonly failed = false,\n private readonly message = ''\n ) {}\n\n print(message: ToMessage<S>): string {\n return (typeof message === 'function' ? message([this.received, this.expected]) : message)\n .replace('{r}', this.ctx.utils.printReceived(this.received))\n .replace('{e}', this.ctx.utils.printExpected(this.expected))\n .replace('{diff}', this.ctx.utils.diff(this.received, this.expected) ?? '');\n }\n\n not(p: (s: S[]) => boolean, message: ToMessage<S>): Check<S> {\n if (this.failed) {\n return this;\n }\n try {\n return new Check<S>(this.ctx, this.received, this.expected, !p([this.received, this.expected]), this.print(message));\n } catch (e: any) {\n return new Check<S>(this.ctx, this.received, this.expected, true, e.message);\n }\n }\n\n undefined(p: (s: S[]) => any, message: ToMessage<S>): Check<S> {\n return this.not(() => isDefined(p([this.received, this.expected])), this.print(message));\n }\n\n else(message: ToMessage<S> = 'Expected {r} not to match with {e}, but it did.'): jest.CustomMatcherResult {\n return {\n pass: !this.failed,\n message: () => (this.failed ? this.message : this.print(message)),\n };\n }\n}\n\nexport const check = <S>(ctx: jest.MatcherContext, received: S, expected?: S): Check<S> => new Check<S>(ctx, received, expected as S);\n\nexport const checkDefined = <S>(ctx: jest.MatcherContext, received: S, expected?: S): Check<S> =>\n new Check<S>(ctx, received, expected as S).undefined(([r]) => r, 'Received array is undefined.').undefined(([, e]) => e, 'Expected array is undefined.');\n"],"mappings":";;AAIA,IAAM,QAAN,MAAM,MAAS;CAEH;CACS;CACA;CACA;CACA;CALnB,YACE,KACA,UACA,UACA,SAA0B,OAC1B,UAA2B,IAC3B;EALQ,KAAA,MAAA;EACS,KAAA,WAAA;EACA,KAAA,WAAA;EACA,KAAA,SAAA;EACA,KAAA,UAAA;CAChB;CAEH,MAAM,SAA+B;EACnC,QAAQ,OAAO,YAAY,aAAa,QAAQ,CAAC,KAAK,UAAU,KAAK,QAAQ,CAAC,IAAI,QAAA,CAC/E,QAAQ,OAAO,KAAK,IAAI,MAAM,cAAc,KAAK,QAAQ,CAAC,CAAC,CAC3D,QAAQ,OAAO,KAAK,IAAI,MAAM,cAAc,KAAK,QAAQ,CAAC,CAAC,CAC3D,QAAQ,UAAU,KAAK,IAAI,MAAM,KAAK,KAAK,UAAU,KAAK,QAAQ,KAAK,EAAE;CAC9E;CAEA,IAAI,GAAwB,SAAiC;EAC3D,IAAI,KAAK,QACP,OAAO;EAET,IAAI;GACF,OAAO,IAAI,MAAS,KAAK,KAAK,KAAK,UAAU,KAAK,UAAU,CAAC,EAAE,CAAC,KAAK,UAAU,KAAK,QAAQ,CAAC,GAAG,KAAK,MAAM,OAAO,CAAC;EACrH,SAAS,GAAQ;GACf,OAAO,IAAI,MAAS,KAAK,KAAK,KAAK,UAAU,KAAK,UAAU,MAAM,EAAE,OAAO;EAC7E;CACF;CAEA,UAAU,GAAoB,SAAiC;EAC7D,OAAO,KAAK,UAAU,UAAU,EAAE,CAAC,KAAK,UAAU,KAAK,QAAQ,CAAC,CAAC,GAAG,KAAK,MAAM,OAAO,CAAC;CACzF;CAEA,KAAK,UAAwB,mDAA6E;EACxG,OAAO;GACL,MAAM,CAAC,KAAK;GACZ,eAAgB,KAAK,SAAS,KAAK,UAAU,KAAK,MAAM,OAAO;EACjE;CACF;AACF;AAEA,MAAa,SAAY,KAA0B,UAAa,aAA2B,IAAI,MAAS,KAAK,UAAU,QAAa;AAEpI,MAAa,gBAAmB,KAA0B,UAAa,aACrE,IAAI,MAAS,KAAK,UAAU,QAAa,CAAC,CAAC,WAAW,CAAC,OAAO,GAAG,8BAA8B,CAAC,CAAC,WAAW,GAAG,OAAO,GAAG,8BAA8B"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Response } from
|
|
1
|
+
import { Response } from "../utils/Response.js";
|
|
2
|
+
//#region src/matchers/HttpMatchers.d.ts
|
|
2
3
|
export declare const toHaveStatus: (res: Response, code: number) => jest.CustomMatcherResult;
|
|
3
4
|
export declare const toBeOk: (res: Response) => jest.CustomMatcherResult;
|
|
4
5
|
export declare const toBeCreated: (res: Response) => jest.CustomMatcherResult;
|
|
@@ -12,20 +13,22 @@ export declare const toBeInternalServerError: (res: Response) => jest.CustomMatc
|
|
|
12
13
|
export declare const toBeBadGateway: (res: Response) => jest.CustomMatcherResult;
|
|
13
14
|
export declare const toBeOkWithItems: (res: Response, length: number) => jest.CustomMatcherResult;
|
|
14
15
|
declare global {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
16
|
+
namespace jest {
|
|
17
|
+
interface Matchers<R, T> {
|
|
18
|
+
toBeOk(): R;
|
|
19
|
+
toBeOkWithItems(length: number): R;
|
|
20
|
+
toBeCreated(): R;
|
|
21
|
+
toHaveNoContent(): R;
|
|
22
|
+
toBeNotFound(): R;
|
|
23
|
+
toBeUnauthorized(): R;
|
|
24
|
+
toBeForbidden(): R;
|
|
25
|
+
toBeBadRequest(): R;
|
|
26
|
+
toBeConflict(): R;
|
|
27
|
+
toBeInternalServerError(): R;
|
|
28
|
+
toBeBadGateway(): R;
|
|
29
|
+
toHaveStatus(code: number): R;
|
|
30
30
|
}
|
|
31
|
+
}
|
|
31
32
|
}
|
|
33
|
+
//#endregion
|
|
34
|
+
//# sourceMappingURL=HttpMatchers.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { match } from "./Match.js";
|
|
2
|
+
//#region src/matchers/HttpMatchers.ts
|
|
3
|
+
const toHaveStatus = (res, code) => match(res).undefined((r) => r, "Response is unknown.").undefined((r) => r?.status?.id, () => "Response does not have a status code").not((r) => r.status.id === code, (r) => `Response does not have code '${code}', but has code '${r.status.id}' instead.`).else(`Response does have status code '${code}'.`);
|
|
4
|
+
const toBeOk = (res) => toHaveStatus(res, 200);
|
|
5
|
+
const toBeCreated = (res) => toHaveStatus(res, 201);
|
|
6
|
+
const toHaveNoContent = (res) => toHaveStatus(res, 204);
|
|
7
|
+
const toBeBadRequest = (res) => toHaveStatus(res, 400);
|
|
8
|
+
const toBeUnauthorized = (res) => toHaveStatus(res, 401);
|
|
9
|
+
const toBeForbidden = (res) => toHaveStatus(res, 403);
|
|
10
|
+
const toBeNotFound = (res) => toHaveStatus(res, 404);
|
|
11
|
+
const toBeConflict = (res) => toHaveStatus(res, 409);
|
|
12
|
+
const toBeInternalServerError = (res) => toHaveStatus(res, 500);
|
|
13
|
+
const toBeBadGateway = (res) => toHaveStatus(res, 502);
|
|
14
|
+
const toBeOkWithItems = (res, length) => match(res).undefined((r) => r.status?.id, "Response did not have a status").not((r) => r.status.id === 200, (r) => `Response did not have status '200'. It had status '${r.status.id}' instead.`).undefined((r) => r?.body?.data?.items, `Response did not have any items.`).not((r) => (r?.body?.data?.itemCount ?? 0) >= length, (r) => `Response did not have at least ${length} items. It only had ${r?.body?.data?.itemCount ?? 0} items.`).else(`Response had status 200 and at least ${length} items`);
|
|
15
|
+
expect.extend({
|
|
16
|
+
toBeOk,
|
|
17
|
+
toBeOkWithItems,
|
|
18
|
+
toBeCreated,
|
|
19
|
+
toHaveNoContent,
|
|
20
|
+
toBeNotFound,
|
|
21
|
+
toBeBadRequest,
|
|
22
|
+
toBeUnauthorized,
|
|
23
|
+
toBeForbidden,
|
|
24
|
+
toBeConflict,
|
|
25
|
+
toBeInternalServerError,
|
|
26
|
+
toHaveStatus,
|
|
27
|
+
toBeBadGateway
|
|
28
|
+
});
|
|
29
|
+
//#endregion
|
|
30
|
+
export { toBeBadGateway, toBeBadRequest, toBeConflict, toBeCreated, toBeForbidden, toBeInternalServerError, toBeNotFound, toBeOk, toBeOkWithItems, toBeUnauthorized, toHaveNoContent, toHaveStatus };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=HttpMatchers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpMatchers.js","names":[],"sources":["../../src/matchers/HttpMatchers.ts"],"sourcesContent":["import { Response } from '../utils/Response';\nimport { match } from './Match';\n\nexport const toHaveStatus = (res: Response, code: number): jest.CustomMatcherResult =>\n match<Response>(res)\n .undefined(r => r, 'Response is unknown.')\n .undefined(\n r => r?.status?.id,\n () => 'Response does not have a status code'\n )\n .not(\n r => r.status.id === code,\n r => `Response does not have code '${code}', but has code '${r.status.id}' instead.`\n )\n .else(`Response does have status code '${code}'.`);\n\nexport const toBeOk = (res: Response): jest.CustomMatcherResult => toHaveStatus(res, 200);\n\nexport const toBeCreated = (res: Response): jest.CustomMatcherResult => toHaveStatus(res, 201);\n\nexport const toHaveNoContent = (res: Response): jest.CustomMatcherResult => toHaveStatus(res, 204);\n\nexport const toBeBadRequest = (res: Response): jest.CustomMatcherResult => toHaveStatus(res, 400);\n\nexport const toBeUnauthorized = (res: Response): jest.CustomMatcherResult => toHaveStatus(res, 401);\n\nexport const toBeForbidden = (res: Response): jest.CustomMatcherResult => toHaveStatus(res, 403);\n\nexport const toBeNotFound = (res: Response): jest.CustomMatcherResult => toHaveStatus(res, 404);\n\nexport const toBeConflict = (res: Response): jest.CustomMatcherResult => toHaveStatus(res, 409);\n\nexport const toBeInternalServerError = (res: Response): jest.CustomMatcherResult => toHaveStatus(res, 500);\n\nexport const toBeBadGateway = (res: Response): jest.CustomMatcherResult => toHaveStatus(res, 502);\n\nexport const toBeOkWithItems = (res: Response, length: number): jest.CustomMatcherResult =>\n match<Response>(res)\n .undefined(r => r.status?.id, 'Response did not have a status')\n .not(\n r => r.status.id === 200,\n r => `Response did not have status '200'. It had status '${r.status.id}' instead.`\n )\n .undefined(r => r?.body?.data?.items, `Response did not have any items.`)\n .not(\n r => (r?.body?.data?.itemCount ?? 0) >= length,\n r => `Response did not have at least ${length} items. It only had ${r?.body?.data?.itemCount ?? 0} items.`\n )\n .else(`Response had status 200 and at least ${length} items`);\n\nexpect.extend({\n toBeOk,\n toBeOkWithItems,\n toBeCreated,\n toHaveNoContent,\n toBeNotFound,\n toBeBadRequest,\n toBeUnauthorized,\n toBeForbidden,\n toBeConflict,\n toBeInternalServerError,\n toHaveStatus,\n toBeBadGateway,\n});\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace jest {\n interface Matchers<R, T> {\n toBeOk(): R;\n toBeOkWithItems(length: number): R;\n toBeCreated(): R;\n toHaveNoContent(): R;\n toBeNotFound(): R;\n toBeUnauthorized(): R;\n toBeForbidden(): R;\n toBeBadRequest(): R;\n toBeConflict(): R;\n toBeInternalServerError(): R;\n toBeBadGateway(): R;\n toHaveStatus(code: number): R;\n }\n }\n}\n"],"mappings":";;AAGA,MAAa,gBAAgB,KAAe,SAC1C,MAAgB,GAAG,CAAC,CACjB,WAAU,MAAK,GAAG,sBAAsB,CAAC,CACzC,WACC,MAAK,GAAG,QAAQ,UACV,sCACR,CAAC,CACA,KACC,MAAK,EAAE,OAAO,OAAO,OACrB,MAAK,gCAAgC,KAAK,mBAAmB,EAAE,OAAO,GAAG,WAC3E,CAAC,CACA,KAAK,mCAAmC,KAAK,GAAG;AAErD,MAAa,UAAU,QAA4C,aAAa,KAAK,GAAG;AAExF,MAAa,eAAe,QAA4C,aAAa,KAAK,GAAG;AAE7F,MAAa,mBAAmB,QAA4C,aAAa,KAAK,GAAG;AAEjG,MAAa,kBAAkB,QAA4C,aAAa,KAAK,GAAG;AAEhG,MAAa,oBAAoB,QAA4C,aAAa,KAAK,GAAG;AAElG,MAAa,iBAAiB,QAA4C,aAAa,KAAK,GAAG;AAE/F,MAAa,gBAAgB,QAA4C,aAAa,KAAK,GAAG;AAE9F,MAAa,gBAAgB,QAA4C,aAAa,KAAK,GAAG;AAE9F,MAAa,2BAA2B,QAA4C,aAAa,KAAK,GAAG;AAEzG,MAAa,kBAAkB,QAA4C,aAAa,KAAK,GAAG;AAEhG,MAAa,mBAAmB,KAAe,WAC7C,MAAgB,GAAG,CAAC,CACjB,WAAU,MAAK,EAAE,QAAQ,IAAI,gCAAgC,CAAC,CAC9D,KACC,MAAK,EAAE,OAAO,OAAO,MACrB,MAAK,sDAAsD,EAAE,OAAO,GAAG,WACzE,CAAC,CACA,WAAU,MAAK,GAAG,MAAM,MAAM,OAAO,kCAAkC,CAAC,CACxE,KACC,OAAM,GAAG,MAAM,MAAM,aAAa,MAAM,SACxC,MAAK,kCAAkC,OAAO,sBAAsB,GAAG,MAAM,MAAM,aAAa,EAAE,QACpG,CAAC,CACA,KAAK,wCAAwC,OAAO,OAAO;AAEhE,OAAO,OAAO;CACZ;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
|
package/dist/matchers/Match.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { Message } from
|
|
1
|
+
import { Message } from "../utils/Types.js";
|
|
2
|
+
//#region src/matchers/Match.d.ts
|
|
2
3
|
export declare class Match<S> {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
private readonly subject;
|
|
5
|
+
private readonly failed;
|
|
6
|
+
private readonly message;
|
|
7
|
+
constructor(subject: S, failed?: boolean, message?: Message<S>);
|
|
8
|
+
not(p: (s: S) => boolean, message: Message<S>): Match<S>;
|
|
9
|
+
undefined(p: (s: S) => any, message: Message<S>): Match<S>;
|
|
10
|
+
else(message: Message<S>): jest.CustomMatcherResult;
|
|
10
11
|
}
|
|
11
12
|
export declare const match: <S>(subject: S) => Match<S>;
|
|
13
|
+
//#endregion
|
|
14
|
+
//# sourceMappingURL=Match.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { isDefined } from "../utils/Utils.js";
|
|
2
|
+
import { toMessage } from "../utils/Types.js";
|
|
3
|
+
//#region src/matchers/Match.ts
|
|
4
|
+
var Match = class Match {
|
|
5
|
+
subject;
|
|
6
|
+
failed;
|
|
7
|
+
message;
|
|
8
|
+
constructor(subject, failed = false, message = "") {
|
|
9
|
+
this.subject = subject;
|
|
10
|
+
this.failed = failed;
|
|
11
|
+
this.message = message;
|
|
12
|
+
}
|
|
13
|
+
not(p, message) {
|
|
14
|
+
if (this.failed) return this;
|
|
15
|
+
try {
|
|
16
|
+
return new Match(this.subject, !p(this.subject), toMessage(message, this.subject));
|
|
17
|
+
} catch (e) {
|
|
18
|
+
return new Match(this.subject, true, e.message);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
undefined(p, message) {
|
|
22
|
+
return this.not(() => isDefined(p(this.subject)), message);
|
|
23
|
+
}
|
|
24
|
+
else(message) {
|
|
25
|
+
return {
|
|
26
|
+
pass: !this.failed,
|
|
27
|
+
message: () => this.failed ? toMessage(this.message) : `${toMessage(message, this.subject)}, which we did not expect.`
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const match = (subject) => new Match(subject);
|
|
32
|
+
//#endregion
|
|
33
|
+
export { Match, match };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=Match.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Match.js","names":[],"sources":["../../src/matchers/Match.ts"],"sourcesContent":["import { isDefined } from '../utils/Utils';\nimport { Message, toMessage } from '../utils/Types';\n\nexport class Match<S> {\n constructor(private readonly subject: S, private readonly failed = false, private readonly message: Message<S> = '') {}\n\n not(p: (s: S) => boolean, message: Message<S>): Match<S> {\n if (this.failed) {\n return this;\n }\n try {\n return new Match<S>(this.subject, !p(this.subject), toMessage(message, this.subject));\n } catch (e: any) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n return new Match<S>(this.subject, true, e.message);\n }\n }\n\n undefined(p: (s: S) => any, message: Message<S>): Match<S> {\n return this.not(() => isDefined(p(this.subject)), message);\n }\n\n else(message: Message<S>): jest.CustomMatcherResult {\n return {\n pass: !this.failed,\n message: () => (this.failed ? toMessage(this.message) : `${toMessage(message, this.subject)}, which we did not expect.`),\n };\n }\n}\n\nexport const match = <S>(subject: S): Match<S> => new Match<S>(subject);\n"],"mappings":";;;AAGA,IAAa,QAAb,MAAa,MAAS;CACS;CAA6B;CAAiC;CAA3F,YAAY,SAA6B,SAA0B,OAAO,UAAuC,IAAI;EAAxF,KAAA,UAAA;EAA6B,KAAA,SAAA;EAAiC,KAAA,UAAA;CAA2B;CAEtH,IAAI,GAAsB,SAA+B;EACvD,IAAI,KAAK,QACP,OAAO;EAET,IAAI;GACF,OAAO,IAAI,MAAS,KAAK,SAAS,CAAC,EAAE,KAAK,OAAO,GAAG,UAAU,SAAS,KAAK,OAAO,CAAC;EACtF,SAAS,GAAQ;GAEf,OAAO,IAAI,MAAS,KAAK,SAAS,MAAM,EAAE,OAAO;EACnD;CACF;CAEA,UAAU,GAAkB,SAA+B;EACzD,OAAO,KAAK,UAAU,UAAU,EAAE,KAAK,OAAO,CAAC,GAAG,OAAO;CAC3D;CAEA,KAAK,SAA+C;EAClD,OAAO;GACL,MAAM,CAAC,KAAK;GACZ,eAAgB,KAAK,SAAS,UAAU,KAAK,OAAO,IAAI,GAAG,UAAU,SAAS,KAAK,OAAO,EAAE;EAC9F;CACF;AACF;AAEA,MAAa,SAAY,YAAyB,IAAI,MAAS,OAAO"}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { Results } from
|
|
1
|
+
import { Results } from "../utils/Types.js";
|
|
2
|
+
//#region src/matchers/ResultMatchers.d.ts
|
|
2
3
|
export declare const toResultWith: (results: Results, message: string) => jest.CustomMatcherResult;
|
|
3
4
|
export declare const toFail: (results: Results) => jest.CustomMatcherResult;
|
|
4
5
|
export declare const toFailWith: (results: Results, message: string) => jest.CustomMatcherResult;
|
|
5
6
|
declare global {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
7
|
+
namespace jest {
|
|
8
|
+
interface Matchers<R, T> {
|
|
9
|
+
toResultWith(message: string): R;
|
|
10
|
+
toFail(): R;
|
|
11
|
+
toFailWith(message: string): R;
|
|
12
12
|
}
|
|
13
|
+
}
|
|
13
14
|
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//# sourceMappingURL=ResultMatchers.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { match } from "./Match.js";
|
|
2
|
+
//#region src/matchers/ResultMatchers.ts
|
|
3
|
+
const notDefined = "Results is not defined.";
|
|
4
|
+
const doesNotFail = "Results does not fail.";
|
|
5
|
+
const hasMessage = (res, message) => res.results.some((r) => r.message === message);
|
|
6
|
+
const messages = (res) => "'" + res?.results.map((r) => r.message).join("', '") + "'";
|
|
7
|
+
const toResultWith = (results, message) => match(results).undefined((r) => r, notDefined).not((r) => hasMessage(r, message), (r) => `Results does not have message '${message}', but it has messages ${messages(r)} instead.`).else(`Succeeds with message ${message}`);
|
|
8
|
+
const toFail = (results) => match(results).undefined((r) => r, notDefined).not((r) => !r.isValid, doesNotFail).else("Results does not fail");
|
|
9
|
+
const toFailWith = (results, message) => match(results).undefined((r) => r, notDefined).not((r) => !r.isValid, doesNotFail).not((r) => hasMessage(r, message), (r) => `Fails, but results does not have message '${message}', but it has messages ${messages(r)} instead.`).else(`Fails with message '${message}'`);
|
|
10
|
+
expect.extend({
|
|
11
|
+
toResultWith,
|
|
12
|
+
toFail,
|
|
13
|
+
toFailWith
|
|
14
|
+
});
|
|
15
|
+
//#endregion
|
|
16
|
+
export { toFail, toFailWith, toResultWith };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=ResultMatchers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResultMatchers.js","names":[],"sources":["../../src/matchers/ResultMatchers.ts"],"sourcesContent":["import { match } from './Match';\nimport { Results } from '../utils/Types';\n\n// Tests for handling Results.\n\nconst notDefined = 'Results is not defined.';\nconst doesNotFail = 'Results does not fail.';\n\nconst hasMessage = (res: Results, message: string) => res.results.some((r: any) => r.message === message);\n\nconst messages = (res: Results): string => \"'\" + res?.results.map(r => r.message).join(\"', '\") + \"'\";\n\nexport const toResultWith = (results: Results, message: string): jest.CustomMatcherResult =>\n match(results)\n .undefined(r => r, notDefined)\n .not(\n r => hasMessage(r, message),\n r => `Results does not have message '${message}', but it has messages ${messages(r)} instead.`\n )\n .else(`Succeeds with message ${message}`);\n\nexport const toFail = (results: Results): jest.CustomMatcherResult =>\n match(results)\n .undefined(r => r, notDefined)\n .not(r => !r.isValid, doesNotFail)\n .else('Results does not fail');\n\nexport const toFailWith = (results: Results, message: string): jest.CustomMatcherResult =>\n match(results)\n .undefined(r => r, notDefined)\n .not(r => !r.isValid, doesNotFail)\n .not(\n r => hasMessage(r, message),\n r => `Fails, but results does not have message '${message}', but it has messages ${messages(r)} instead.`\n )\n .else(`Fails with message '${message}'`);\n\nexpect.extend({\n toResultWith,\n toFail: toFail,\n toFailWith: toFailWith,\n});\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace jest {\n interface Matchers<R, T> {\n toResultWith(message: string): R;\n toFail(): R;\n toFailWith(message: string): R;\n }\n }\n}\n"],"mappings":";;AAKA,MAAM,aAAa;AACnB,MAAM,cAAc;AAEpB,MAAM,cAAc,KAAc,YAAoB,IAAI,QAAQ,MAAM,MAAW,EAAE,YAAY,OAAO;AAExG,MAAM,YAAY,QAAyB,MAAM,KAAK,QAAQ,KAAI,MAAK,EAAE,OAAO,CAAC,CAAC,KAAK,MAAM,IAAI;AAEjG,MAAa,gBAAgB,SAAkB,YAC7C,MAAM,OAAO,CAAC,CACX,WAAU,MAAK,GAAG,UAAU,CAAC,CAC7B,KACC,MAAK,WAAW,GAAG,OAAO,IAC1B,MAAK,kCAAkC,QAAQ,yBAAyB,SAAS,CAAC,EAAE,UACtF,CAAC,CACA,KAAK,yBAAyB,SAAS;AAE5C,MAAa,UAAU,YACrB,MAAM,OAAO,CAAC,CACX,WAAU,MAAK,GAAG,UAAU,CAAC,CAC7B,KAAI,MAAK,CAAC,EAAE,SAAS,WAAW,CAAC,CACjC,KAAK,uBAAuB;AAEjC,MAAa,cAAc,SAAkB,YAC3C,MAAM,OAAO,CAAC,CACX,WAAU,MAAK,GAAG,UAAU,CAAC,CAC7B,KAAI,MAAK,CAAC,EAAE,SAAS,WAAW,CAAC,CACjC,KACC,MAAK,WAAW,GAAG,OAAO,IAC1B,MAAK,6CAA6C,QAAQ,yBAAyB,SAAS,CAAC,EAAE,UACjG,CAAC,CACA,KAAK,uBAAuB,QAAQ,EAAE;AAE3C,OAAO,OAAO;CACZ;CACQ;CACI;AACd,CAAC"}
|
package/dist/matchers/index.d.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
import { toBeBadGateway, toBeBadRequest, toBeConflict, toBeCreated, toBeForbidden, toBeInternalServerError, toBeNotFound, toBeOk, toBeOkWithItems, toBeUnauthorized, toHaveNoContent, toHaveStatus } from "./HttpMatchers.js";
|
|
2
|
+
import { Match, match } from "./Match.js";
|
|
3
|
+
import { check, checkDefined } from "./Check.js";
|
|
4
|
+
import { toFail, toFailWith, toResultWith } from "./ResultMatchers.js";
|
|
5
|
+
import { toBeArrayOf } from "./toBeArrayOf.js";
|
|
6
|
+
import { toBeArrayOfWithLength } from "./toBeArrayOfWithLength.js";
|
|
7
|
+
import { toBeAt } from "./toBeAt.js";
|
|
8
|
+
import { toBeExactlyAt } from "./toBeExactlyAt.js";
|
|
9
|
+
import { Fails, FailsWith, toFailMatcher, toFailMatcherWith } from "./toFailMatcher.js";
|
|
10
|
+
import { toBeValid } from "./toBeValid.js";
|
|
11
|
+
import { toMatchArray } from "./toMatchArray.js";
|
|
12
|
+
import { MatchesExactJson, toMatchExactJson } from "./toMatchExactJson.js";
|
|
13
|
+
import { toMatchException } from "./toMatchException.js";
|
|
14
|
+
import { MatchesJson, toMatchJson } from "./toMatchJson.js";
|
|
15
|
+
import { toMatchRoute } from "./toMatchRoute.js";
|
|
16
|
+
import { toMatchText } from "./toMatchText.js";
|
|
17
|
+
import { Passes, PassesWith, toPassMatcher, toPassMatcherWith } from "./toPassMatcher.js";
|
|
18
|
+
import { toBeQueriedWith } from "./toBeQueriedWith.js";
|
|
19
|
+
import { toBeRoutedTo, toMatchAsString, weExpectedButReceivedInstead } from "./toBeRoutedTo.js";
|
|
20
|
+
export { Fails, FailsWith, Match, MatchesExactJson, MatchesJson, Passes, PassesWith, check, checkDefined, match, toBeArrayOf, toBeArrayOfWithLength, toBeAt, toBeBadGateway, toBeBadRequest, toBeConflict, toBeCreated, toBeExactlyAt, toBeForbidden, toBeInternalServerError, toBeNotFound, toBeOk, toBeOkWithItems, toBeQueriedWith, toBeRoutedTo, toBeUnauthorized, toBeValid, toFail, toFailMatcher, toFailMatcherWith, toFailWith, toHaveNoContent, toHaveStatus, toMatchArray, toMatchAsString, toMatchExactJson, toMatchException, toMatchJson, toMatchRoute, toMatchText, toPassMatcher, toPassMatcherWith, toResultWith, weExpectedButReceivedInstead };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Match, match } from "./Match.js";
|
|
2
|
+
import { toBeBadGateway, toBeBadRequest, toBeConflict, toBeCreated, toBeForbidden, toBeInternalServerError, toBeNotFound, toBeOk, toBeOkWithItems, toBeUnauthorized, toHaveNoContent, toHaveStatus } from "./HttpMatchers.js";
|
|
3
|
+
import { check, checkDefined } from "./Check.js";
|
|
4
|
+
import { toFail, toFailWith, toResultWith } from "./ResultMatchers.js";
|
|
5
|
+
import { toBeArrayOf } from "./toBeArrayOf.js";
|
|
6
|
+
import { toBeArrayOfWithLength } from "./toBeArrayOfWithLength.js";
|
|
7
|
+
import { toBeAt } from "./toBeAt.js";
|
|
8
|
+
import { toBeExactlyAt } from "./toBeExactlyAt.js";
|
|
9
|
+
import { Fails, FailsWith, toFailMatcher, toFailMatcherWith } from "./toFailMatcher.js";
|
|
10
|
+
import { toBeValid } from "./toBeValid.js";
|
|
11
|
+
import { toMatchArray } from "./toMatchArray.js";
|
|
12
|
+
import { MatchesExactJson, toMatchExactJson } from "./toMatchExactJson.js";
|
|
13
|
+
import { toMatchException } from "./toMatchException.js";
|
|
14
|
+
import { MatchesJson, toMatchJson } from "./toMatchJson.js";
|
|
15
|
+
import { toMatchRoute } from "./toMatchRoute.js";
|
|
16
|
+
import { toMatchText } from "./toMatchText.js";
|
|
17
|
+
import { Passes, PassesWith, toPassMatcher, toPassMatcherWith } from "./toPassMatcher.js";
|
|
18
|
+
import { toBeQueriedWith } from "./toBeQueriedWith.js";
|
|
19
|
+
import { toBeRoutedTo, toMatchAsString, weExpectedButReceivedInstead } from "./toBeRoutedTo.js";
|
|
20
|
+
export { Fails, FailsWith, Match, MatchesExactJson, MatchesJson, Passes, PassesWith, check, checkDefined, match, toBeArrayOf, toBeArrayOfWithLength, toBeAt, toBeBadGateway, toBeBadRequest, toBeConflict, toBeCreated, toBeExactlyAt, toBeForbidden, toBeInternalServerError, toBeNotFound, toBeOk, toBeOkWithItems, toBeQueriedWith, toBeRoutedTo, toBeUnauthorized, toBeValid, toFail, toFailMatcher, toFailMatcherWith, toFailWith, toHaveNoContent, toHaveStatus, toMatchArray, toMatchAsString, toMatchExactJson, toMatchException, toMatchJson, toMatchRoute, toMatchText, toPassMatcher, toPassMatcherWith, toResultWith, weExpectedButReceivedInstead };
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { Constructor
|
|
2
|
-
|
|
1
|
+
import { Constructor } from "../utils/Types.js";
|
|
2
|
+
//#region src/matchers/toBeArrayOf.d.ts
|
|
3
|
+
export declare const toBeArrayOf: <T>(items: unknown, ctor: Constructor<T>) => jest.CustomMatcherResult;
|
|
3
4
|
declare global {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
5
|
+
namespace jest {
|
|
6
|
+
interface Matchers<R, T> {
|
|
7
|
+
toBeArrayOf<Z>(ctor: Constructor<Z>): R;
|
|
8
8
|
}
|
|
9
|
+
}
|
|
9
10
|
}
|
|
11
|
+
//#endregion
|
|
12
|
+
//# sourceMappingURL=toBeArrayOf.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { match } from "./Match.js";
|
|
2
|
+
//#region src/matchers/toBeArrayOf.ts
|
|
3
|
+
const toBeArrayOf = (items, ctor) => match(items).undefined((it) => it, "Subject is undefined.").not((it) => it instanceof Array, "Subject is not an array.").not((it) => it.every((i) => i instanceof ctor), `Not all elements are of type '${ctor.name}'.`).else(`All elements in array are of type '${ctor.name}'`);
|
|
4
|
+
expect.extend({ toBeArrayOf });
|
|
5
|
+
//#endregion
|
|
6
|
+
export { toBeArrayOf };
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=toBeArrayOf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toBeArrayOf.js","names":[],"sources":["../../src/matchers/toBeArrayOf.ts"],"sourcesContent":["import { Constructor as Ctor } from '../utils/Types';\nimport { match } from './Match';\n\nexport const toBeArrayOf = <T>(items: unknown, ctor: Ctor<T>): jest.CustomMatcherResult =>\n match<unknown>(items)\n .undefined(it => it, 'Subject is undefined.')\n .not(it => it instanceof Array, 'Subject is not an array.')\n .not(it => (it as []).every((i: any) => i instanceof ctor), `Not all elements are of type '${ctor.name}'.`)\n .else(`All elements in array are of type '${ctor.name}'`);\n\nexpect.extend({\n toBeArrayOf,\n});\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace jest {\n interface Matchers<R, T> {\n toBeArrayOf<Z>(ctor: Ctor<Z>): R;\n }\n }\n}\n"],"mappings":";;AAGA,MAAa,eAAkB,OAAgB,SAC7C,MAAe,KAAK,CAAC,CAClB,WAAU,OAAM,IAAI,uBAAuB,CAAC,CAC5C,KAAI,OAAM,cAAc,OAAO,0BAA0B,CAAC,CAC1D,KAAI,OAAO,GAAU,OAAO,MAAW,aAAa,IAAI,GAAG,iCAAiC,KAAK,KAAK,GAAG,CAAC,CAC1G,KAAK,sCAAsC,KAAK,KAAK,EAAE;AAE5D,OAAO,OAAO,EACZ,YACF,CAAC"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { Constructor
|
|
2
|
-
|
|
1
|
+
import { Constructor } from "../utils/Types.js";
|
|
2
|
+
//#region src/matchers/toBeArrayOfWithLength.d.ts
|
|
3
|
+
export declare const toBeArrayOfWithLength: <T>(items: unknown, ctor: Constructor<T>, length: number) => jest.CustomMatcherResult;
|
|
3
4
|
declare global {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
5
|
+
namespace jest {
|
|
6
|
+
interface Matchers<R, T> {
|
|
7
|
+
toBeArrayOfWithLength<Z>(ctor: Constructor<Z>, length: number): R;
|
|
8
8
|
}
|
|
9
|
+
}
|
|
9
10
|
}
|
|
11
|
+
//#endregion
|
|
12
|
+
//# sourceMappingURL=toBeArrayOfWithLength.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { match } from "./Match.js";
|
|
2
|
+
//#region src/matchers/toBeArrayOfWithLength.ts
|
|
3
|
+
const toBeArrayOfWithLength = (items, ctor, length) => match(items).undefined((it) => it, "Subject is undefined.").not((it) => it instanceof Array, "Subject is not an array.").not((it) => it.length === length, (it) => `Subject does not have ${length} elements, but ${it.length}.`).not((it) => it.every((i) => i instanceof ctor), `Not all elements are of type '${ctor.name}'.`).else(`Subject has ${length} elements, which are all of type '${ctor.name}'`);
|
|
4
|
+
expect.extend({ toBeArrayOfWithLength });
|
|
5
|
+
//#endregion
|
|
6
|
+
export { toBeArrayOfWithLength };
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=toBeArrayOfWithLength.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toBeArrayOfWithLength.js","names":[],"sources":["../../src/matchers/toBeArrayOfWithLength.ts"],"sourcesContent":["import { Constructor as Ctor } from '../utils/Types';\nimport { match } from './Match';\n\nexport const toBeArrayOfWithLength = <T>(items: unknown, ctor: Ctor<T>, length: number): jest.CustomMatcherResult =>\n match<unknown>(items)\n .undefined(it => it, 'Subject is undefined.')\n .not(it => it instanceof Array, 'Subject is not an array.')\n .not(\n it => (it as []).length === length,\n it => `Subject does not have ${length} elements, but ${(it as []).length}.`\n )\n .not(it => (it as []).every((i: any) => i instanceof ctor), `Not all elements are of type '${ctor.name}'.`)\n .else(`Subject has ${length} elements, which are all of type '${ctor.name}'`);\n\nexpect.extend({\n toBeArrayOfWithLength,\n});\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace jest {\n interface Matchers<R, T> {\n toBeArrayOfWithLength<Z>(ctor: Ctor<Z>, length: number): R;\n }\n }\n}\n"],"mappings":";;AAGA,MAAa,yBAA4B,OAAgB,MAAe,WACtE,MAAe,KAAK,CAAC,CAClB,WAAU,OAAM,IAAI,uBAAuB,CAAC,CAC5C,KAAI,OAAM,cAAc,OAAO,0BAA0B,CAAC,CAC1D,KACC,OAAO,GAAU,WAAW,SAC5B,OAAM,yBAAyB,OAAO,iBAAkB,GAAU,OAAO,EAC3E,CAAC,CACA,KAAI,OAAO,GAAU,OAAO,MAAW,aAAa,IAAI,GAAG,iCAAiC,KAAK,KAAK,GAAG,CAAC,CAC1G,KAAK,eAAe,OAAO,oCAAoC,KAAK,KAAK,EAAE;AAEhF,OAAO,OAAO,EACZ,sBACF,CAAC"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { Id, Tester, UseCase } from
|
|
1
|
+
import { Id, Tester, UseCase } from "../utils/Types.js";
|
|
2
|
+
//#region src/matchers/toBeAt.d.ts
|
|
2
3
|
export declare const toBeAt: (tester?: Tester, uc?: UseCase, id?: Id) => jest.CustomMatcherResult;
|
|
3
4
|
declare global {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
5
|
+
namespace jest {
|
|
6
|
+
interface Matchers<R, T> {
|
|
7
|
+
toBeAt(uc?: UseCase, id?: Id): R;
|
|
8
8
|
}
|
|
9
|
+
}
|
|
9
10
|
}
|
|
11
|
+
//#endregion
|
|
12
|
+
//# sourceMappingURL=toBeAt.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { match } from "./Match.js";
|
|
2
|
+
//#region src/matchers/toBeAt.ts
|
|
3
|
+
const toBeAt = (tester, uc, id) => {
|
|
4
|
+
return match(tester).undefined((t) => t, "Tester is undefined").undefined((t) => t.url, "Tester does not contain a URL").undefined(() => uc, "Use case is undefined").not((t) => t.url.includes(`/${uc?.app.id}`), (t) => `We expected the tester to be at app '${uc?.app.id}', but it is at '${t?.url}' instead.`).not((t) => t.url.includes(`/${uc?.id}`), (t) => `We expected the tester to be at use case '${uc?.id}', but it is at '${t?.url}' instead.`).not((t) => t.url.includes(id ? `/${id}` : ""), (t) => `We expected the path to contain '/42', but it is '${t?.url}' instead.`).else((t) => `The tester is at '${t?.url}'`);
|
|
5
|
+
};
|
|
6
|
+
expect.extend({ toBeAt });
|
|
7
|
+
//#endregion
|
|
8
|
+
export { toBeAt };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=toBeAt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toBeAt.js","names":[],"sources":["../../src/matchers/toBeAt.ts"],"sourcesContent":["import { Id, Tester, UseCase } from '../utils/Types';\nimport { match } from './Match';\n\nexport const toBeAt = (tester?: Tester, uc?: UseCase, id?: Id): jest.CustomMatcherResult => {\n return match<Tester>(tester as Tester)\n .undefined(t => t, 'Tester is undefined')\n .undefined(t => t.url, 'Tester does not contain a URL')\n .undefined(() => uc, 'Use case is undefined')\n .not(\n t => t.url.includes(`/${uc?.app.id}`),\n t => `We expected the tester to be at app '${uc?.app.id}', but it is at '${t?.url}' instead.`\n )\n .not(\n t => t.url.includes(`/${uc?.id}`),\n t => `We expected the tester to be at use case '${uc?.id}', but it is at '${t?.url}' instead.`\n )\n .not(\n t => t.url.includes(id ? `/${id}` : ''),\n t => `We expected the path to contain '/42', but it is '${t?.url}' instead.`\n )\n .else(t => `The tester is at '${t?.url}'`);\n};\n\nexpect.extend({\n toBeAt,\n});\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace jest {\n interface Matchers<R, T> {\n toBeAt(uc?: UseCase, id?: Id): R;\n }\n }\n}\n"],"mappings":";;AAGA,MAAa,UAAU,QAAiB,IAAc,OAAsC;CAC1F,OAAO,MAAc,MAAgB,CAAC,CACnC,WAAU,MAAK,GAAG,qBAAqB,CAAC,CACxC,WAAU,MAAK,EAAE,KAAK,+BAA+B,CAAC,CACtD,gBAAgB,IAAI,uBAAuB,CAAC,CAC5C,KACC,MAAK,EAAE,IAAI,SAAS,IAAI,IAAI,IAAI,IAAI,IACpC,MAAK,wCAAwC,IAAI,IAAI,GAAG,mBAAmB,GAAG,IAAI,WACpF,CAAC,CACA,KACC,MAAK,EAAE,IAAI,SAAS,IAAI,IAAI,IAAI,IAChC,MAAK,6CAA6C,IAAI,GAAG,mBAAmB,GAAG,IAAI,WACrF,CAAC,CACA,KACC,MAAK,EAAE,IAAI,SAAS,KAAK,IAAI,OAAO,EAAE,IACtC,MAAK,qDAAqD,GAAG,IAAI,WACnE,CAAC,CACA,MAAK,MAAK,qBAAqB,GAAG,IAAI,EAAE;AAC7C;AAEA,OAAO,OAAO,EACZ,OACF,CAAC"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { Id, Tester, UseCase } from
|
|
1
|
+
import { Id, Tester, UseCase } from "../utils/Types.js";
|
|
2
|
+
//#region src/matchers/toBeExactlyAt.d.ts
|
|
2
3
|
export declare const toBeExactlyAt: (tester?: Tester, uc?: UseCase, id?: Id) => jest.CustomMatcherResult;
|
|
3
4
|
declare global {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
5
|
+
namespace jest {
|
|
6
|
+
interface Matchers<R, T> {
|
|
7
|
+
toBeExactlyAt(uc?: UseCase, id?: Id): R;
|
|
8
8
|
}
|
|
9
|
+
}
|
|
9
10
|
}
|
|
11
|
+
//#endregion
|
|
12
|
+
//# sourceMappingURL=toBeExactlyAt.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isDefined } from "../utils/Utils.js";
|
|
2
|
+
import { match } from "./Match.js";
|
|
3
|
+
//#region src/matchers/toBeExactlyAt.ts
|
|
4
|
+
const toUrl = (uc, id) => {
|
|
5
|
+
const i = isDefined(id) ? `/${id}` : "";
|
|
6
|
+
return `/${uc.app.id}/${uc.id}${i}`;
|
|
7
|
+
};
|
|
8
|
+
const toBeExactlyAt = (tester, uc, id) => {
|
|
9
|
+
return match(tester).undefined((t) => t, "Tester is undefined").undefined((t) => t.url, "Tester does not contain a URL").undefined(() => uc, "Use case is undefined").not((t) => t.url.includes(toUrl(uc, id)), (t) => `We expected the tester to be at: '${toUrl(uc, id)}', but it is at: '${t?.url}' instead.`).else((t) => `The tester is at '${t?.url}'`);
|
|
10
|
+
};
|
|
11
|
+
expect.extend({ toBeExactlyAt });
|
|
12
|
+
//#endregion
|
|
13
|
+
export { toBeExactlyAt };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=toBeExactlyAt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toBeExactlyAt.js","names":[],"sources":["../../src/matchers/toBeExactlyAt.ts"],"sourcesContent":["import { Id, Tester, UseCase } from '../utils/Types';\nimport { isDefined } from '../utils/Utils';\nimport { match } from './Match';\n\nconst toUrl = (uc: UseCase, id?: Id): string => {\n const i = isDefined(id) ? `/${id}` : '';\n return `/${uc.app.id}/${uc.id}${i}`;\n};\n\nexport const toBeExactlyAt = (tester?: Tester, uc?: UseCase, id?: Id): jest.CustomMatcherResult => {\n return match<Tester>(tester as Tester)\n .undefined(t => t, 'Tester is undefined')\n .undefined(t => t.url, 'Tester does not contain a URL')\n .undefined(() => uc, 'Use case is undefined')\n .not(\n t => t.url.includes(toUrl(uc as UseCase, id)),\n t => `We expected the tester to be at: '${toUrl(uc as UseCase, id)}', but it is at: '${t?.url}' instead.`\n )\n .else(t => `The tester is at '${t?.url}'`);\n};\n\nexpect.extend({\n toBeExactlyAt,\n});\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace jest {\n interface Matchers<R, T> {\n toBeExactlyAt(uc?: UseCase, id?: Id): R;\n }\n }\n}\n"],"mappings":";;;AAIA,MAAM,SAAS,IAAa,OAAoB;CAC9C,MAAM,IAAI,UAAU,EAAE,IAAI,IAAI,OAAO;CACrC,OAAO,IAAI,GAAG,IAAI,GAAG,GAAG,GAAG,KAAK;AAClC;AAEA,MAAa,iBAAiB,QAAiB,IAAc,OAAsC;CACjG,OAAO,MAAc,MAAgB,CAAC,CACnC,WAAU,MAAK,GAAG,qBAAqB,CAAC,CACxC,WAAU,MAAK,EAAE,KAAK,+BAA+B,CAAC,CACtD,gBAAgB,IAAI,uBAAuB,CAAC,CAC5C,KACC,MAAK,EAAE,IAAI,SAAS,MAAM,IAAe,EAAE,CAAC,IAC5C,MAAK,qCAAqC,MAAM,IAAe,EAAE,EAAE,oBAAoB,GAAG,IAAI,WAChG,CAAC,CACA,MAAK,MAAK,qBAAqB,GAAG,IAAI,EAAE;AAC7C;AAEA,OAAO,OAAO,EACZ,cACF,CAAC"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { Query } from
|
|
1
|
+
import { Query } from "../utils/Types.js";
|
|
2
|
+
//#region src/matchers/toBeQueriedWith.d.ts
|
|
2
3
|
export declare const toBeQueriedWith: (query: jest.Mock, expected: Query) => jest.CustomMatcherResult;
|
|
3
4
|
declare global {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
5
|
+
namespace jest {
|
|
6
|
+
interface Matchers<R, T> {
|
|
7
|
+
toBeQueriedWith(expected: Query): R;
|
|
8
8
|
}
|
|
9
|
+
}
|
|
9
10
|
}
|
|
11
|
+
//#endregion
|
|
12
|
+
//# sourceMappingURL=toBeQueriedWith.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { match } from "./Match.js";
|
|
2
|
+
//#region src/matchers/toBeQueriedWith.ts
|
|
3
|
+
const toBeQueriedWith = (query, expected) => match(query?.mock?.calls).undefined((c) => c, "Query is unknown.").not((c) => c.length === 1, "Query did not execute.").not((c) => c[0][0].toString() === expected?.toString(), (c) => `We expected query '${expected}', but we received query '${c[0][0]}' instead.`).else(`Received query does match '${expected}'`);
|
|
4
|
+
expect.extend({ toBeQueriedWith });
|
|
5
|
+
//#endregion
|
|
6
|
+
export { toBeQueriedWith };
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=toBeQueriedWith.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toBeQueriedWith.js","names":[],"sources":["../../src/matchers/toBeQueriedWith.ts"],"sourcesContent":["import { match } from './Match';\nimport { Query } from '../utils/Types';\n\nexport const toBeQueriedWith = (query: jest.Mock, expected: Query): jest.CustomMatcherResult =>\n match<any[]>(query?.mock?.calls)\n .undefined(c => c, 'Query is unknown.')\n .not(c => c.length === 1, 'Query did not execute.')\n .not(\n c => c[0][0].toString() === expected?.toString(),\n c => `We expected query '${expected}', but we received query '${c[0][0]}' instead.`\n )\n .else(`Received query does match '${expected}'`);\n\nexpect.extend({\n toBeQueriedWith: toBeQueriedWith,\n});\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace jest {\n interface Matchers<R, T> {\n toBeQueriedWith(expected: Query): R;\n }\n }\n}\n"],"mappings":";;AAGA,MAAa,mBAAmB,OAAkB,aAChD,MAAa,OAAO,MAAM,KAAK,CAAC,CAC7B,WAAU,MAAK,GAAG,mBAAmB,CAAC,CACtC,KAAI,MAAK,EAAE,WAAW,GAAG,wBAAwB,CAAC,CAClD,KACC,MAAK,EAAE,EAAE,CAAC,EAAE,CAAC,SAAS,MAAM,UAAU,SAAS,IAC/C,MAAK,sBAAsB,SAAS,4BAA4B,EAAE,EAAE,CAAC,GAAG,WAC1E,CAAC,CACA,KAAK,8BAA8B,SAAS,EAAE;AAEnD,OAAO,OAAO,EACK,gBACnB,CAAC"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { Uri } from
|
|
1
|
+
import { Uri } from "../utils/Types.js";
|
|
2
|
+
//#region src/matchers/toBeRoutedTo.d.ts
|
|
2
3
|
export declare const weExpectedButReceivedInstead: ([r, e]: [any, any]) => string;
|
|
3
4
|
export declare function toMatchAsString(this: jest.MatcherContext, received: unknown, expected: unknown): jest.CustomMatcherResult;
|
|
4
5
|
export declare const toBeRoutedTo: (query: jest.Mock, expected: Uri) => jest.CustomMatcherResult;
|
|
5
6
|
declare global {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
7
|
+
namespace jest {
|
|
8
|
+
interface Matchers<R, T> {
|
|
9
|
+
toBeRoutedTo(uri: Uri): R;
|
|
10
10
|
}
|
|
11
|
+
}
|
|
11
12
|
}
|
|
13
|
+
//#endregion
|
|
14
|
+
//# sourceMappingURL=toBeRoutedTo.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { asString } from "../utils/Utils.js";
|
|
2
|
+
import { match } from "./Match.js";
|
|
3
|
+
import { checkDefined } from "./Check.js";
|
|
4
|
+
//#region src/matchers/toBeRoutedTo.ts
|
|
5
|
+
const weExpectedButReceivedInstead = ([r, e]) => `We expected ${asString(e)}, but we received '${asString(r)}' instead.`;
|
|
6
|
+
function toMatchAsString(received, expected) {
|
|
7
|
+
return checkDefined(this, received, expected).not(([r, e]) => this.equals(asString(r), asString(e)), ([r, e]) => weExpectedButReceivedInstead([r, e])).else();
|
|
8
|
+
}
|
|
9
|
+
const toBeRoutedTo = (query, expected) => match(query?.mock?.calls).undefined((c) => c, "Uri is unknown.").not((c) => c.length === 1, "Method was not called.").not((c) => asString(c[0][0]) === asString(expected), (c) => `We expected uri '${asString(expected)}', but we received uri '${asString(c[0][0])}' instead.`).else(`Called uri does match '${asString(expected)}'`);
|
|
10
|
+
expect.extend({ toBeRoutedTo });
|
|
11
|
+
//#endregion
|
|
12
|
+
export { toBeRoutedTo, toMatchAsString, weExpectedButReceivedInstead };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=toBeRoutedTo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toBeRoutedTo.js","names":[],"sources":["../../src/matchers/toBeRoutedTo.ts"],"sourcesContent":["import { checkDefined } from './Check';\nimport { Uri } from '../utils/Types';\nimport { asString } from '../utils/Utils';\nimport { match } from './Match';\n\nexport const weExpectedButReceivedInstead = ([r, e]: [any, any]) => `We expected ${asString(e)}, but we received '${asString(r)}' instead.`;\n\nexport function toMatchAsString(this: jest.MatcherContext, received: unknown, expected: unknown): jest.CustomMatcherResult {\n return checkDefined(this, received, expected)\n .not(\n ([r, e]) => this.equals(asString(r), asString(e)),\n ([r, e]) => weExpectedButReceivedInstead([r, e])\n )\n .else();\n}\n\n// export function toBeRoutedTo(this: jest.MatcherContext, query: jest.Mock, expected: Uri): jest.CustomMatcherResult {\n// return check<any[]>(this, query?.mock?.calls)\n// .undefined(r => r, \"Uri is unknown.\")\n// .not(r => r.length === 1, \"Method was not called.\")\n// .not(r => this.equals(asString(r[0][0]), asString(expected)), ([r,e]) => weExpectedButReceivedInstead([r[0][0], e]))\n// .else();\n// }\n\nexport const toBeRoutedTo = (query: jest.Mock, expected: Uri): jest.CustomMatcherResult =>\n match<any[]>(query?.mock?.calls)\n .undefined(c => c, 'Uri is unknown.')\n .not(c => c.length === 1, 'Method was not called.')\n .not(\n c => asString(c[0][0]) === asString(expected),\n c => `We expected uri '${asString(expected)}', but we received uri '${asString(c[0][0])}' instead.`\n )\n .else(`Called uri does match '${asString(expected)}'`);\n\nexpect.extend({\n toBeRoutedTo: toBeRoutedTo,\n});\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace jest {\n interface Matchers<R, T> {\n toBeRoutedTo(uri: Uri): R;\n }\n }\n}\n"],"mappings":";;;;AAKA,MAAa,gCAAgC,CAAC,GAAG,OAAmB,eAAe,SAAS,CAAC,EAAE,qBAAqB,SAAS,CAAC,EAAE;AAEhI,SAAgB,gBAA2C,UAAmB,UAA6C;CACzH,OAAO,aAAa,MAAM,UAAU,QAAQ,CAAC,CAC1C,KACE,CAAC,GAAG,OAAO,KAAK,OAAO,SAAS,CAAC,GAAG,SAAS,CAAC,CAAC,IAC/C,CAAC,GAAG,OAAO,6BAA6B,CAAC,GAAG,CAAC,CAAC,CACjD,CAAC,CACA,KAAK;AACV;AAUA,MAAa,gBAAgB,OAAkB,aAC7C,MAAa,OAAO,MAAM,KAAK,CAAC,CAC7B,WAAU,MAAK,GAAG,iBAAiB,CAAC,CACpC,KAAI,MAAK,EAAE,WAAW,GAAG,wBAAwB,CAAC,CAClD,KACC,MAAK,SAAS,EAAE,EAAE,CAAC,EAAE,MAAM,SAAS,QAAQ,IAC5C,MAAK,oBAAoB,SAAS,QAAQ,EAAE,0BAA0B,SAAS,EAAE,EAAE,CAAC,EAAE,EAAE,WAC1F,CAAC,CACA,KAAK,0BAA0B,SAAS,QAAQ,EAAE,EAAE;AAEzD,OAAO,OAAO,EACE,aAChB,CAAC"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
//#region src/matchers/toBeValid.d.ts
|
|
1
2
|
export declare const toBeValid: (v?: unknown) => jest.CustomMatcherResult;
|
|
2
3
|
declare global {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
4
|
+
namespace jest {
|
|
5
|
+
interface Matchers<R, T> {
|
|
6
|
+
toBeValid(): R;
|
|
7
7
|
}
|
|
8
|
+
}
|
|
8
9
|
}
|
|
10
|
+
//#endregion
|
|
11
|
+
//# sourceMappingURL=toBeValid.d.ts.map
|