@thisisagile/easy-test 15.2.0 → 15.2.3

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.
@@ -0,0 +1,18 @@
1
+ /// <reference types="jest" />
2
+ import CustomMatcherResult = jest.CustomMatcherResult;
3
+ type ToMessage<S> = string | ((s: S[]) => string);
4
+ declare class Check<S> {
5
+ private ctx;
6
+ private readonly received;
7
+ private readonly expected;
8
+ private readonly failed;
9
+ private readonly message;
10
+ constructor(ctx: jest.MatcherContext, received: S, expected: S, failed?: boolean, message?: string);
11
+ print(message: ToMessage<S>): string;
12
+ not(p: (s: (S)[]) => boolean, message: ToMessage<S>): Check<S>;
13
+ undefined(p: (s: (S)[]) => any, message: ToMessage<S>): Check<S>;
14
+ else(message?: ToMessage<S>): CustomMatcherResult;
15
+ }
16
+ export declare const check: <S>(ctx: jest.MatcherContext, received: S, expected?: S | undefined) => Check<S>;
17
+ export declare const checkDefined: <S>(ctx: jest.MatcherContext, received: S, expected?: S | undefined) => Check<S>;
18
+ export {};
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkDefined = exports.check = void 0;
4
+ const Utils_1 = require("../utils/Utils");
5
+ class Check {
6
+ constructor(ctx, received, expected, failed = false, message = "") {
7
+ this.ctx = ctx;
8
+ this.received = received;
9
+ this.expected = expected;
10
+ this.failed = failed;
11
+ this.message = message;
12
+ }
13
+ print(message) {
14
+ return (typeof message === "function" ? message([this.received, this.expected]) : message)
15
+ .replace("{r}", this.ctx.utils.printReceived(this.received))
16
+ .replace("{e}", this.ctx.utils.printExpected(this.expected))
17
+ .replace("{diff}", this.ctx.utils.diff(this.received, this.expected) ?? "");
18
+ }
19
+ not(p, message) {
20
+ if (this.failed) {
21
+ return this;
22
+ }
23
+ try {
24
+ return new Check(this.ctx, this.received, this.expected, !p([this.received, this.expected]), this.print(message));
25
+ }
26
+ catch (e) {
27
+ return new Check(this.ctx, this.received, this.expected, true, e.message);
28
+ }
29
+ }
30
+ undefined(p, message) {
31
+ return this.not(() => (0, Utils_1.isDefined)(p([this.received, this.expected])), this.print(message));
32
+ }
33
+ else(message = "Expected {r} not to match with {e}, but it did.") {
34
+ return {
35
+ pass: !this.failed,
36
+ message: () => (this.failed ? this.message : this.print(message))
37
+ };
38
+ }
39
+ }
40
+ const check = (ctx, received, expected) => new Check(ctx, received, expected);
41
+ exports.check = check;
42
+ const checkDefined = (ctx, received, expected) => new Check(ctx, received, expected)
43
+ .undefined(([r]) => r, "Received array is undefined.")
44
+ .undefined(([, e]) => e, "Expected array is undefined.");
45
+ exports.checkDefined = checkDefined;
46
+ //# sourceMappingURL=Check.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Check.js","sourceRoot":"","sources":["../../src/matchers/Check.ts"],"names":[],"mappings":";;;AAAA,0CAA2C;AAM3C,MAAM,KAAK;IACT,YAAoB,GAAwB,EAAmB,QAAW,EAAmB,QAAW,EAAmB,SAAS,KAAK,EAAmB,UAAU,EAAE;QAApJ,QAAG,GAAH,GAAG,CAAqB;QAAmB,aAAQ,GAAR,QAAQ,CAAG;QAAmB,aAAQ,GAAR,QAAQ,CAAG;QAAmB,WAAM,GAAN,MAAM,CAAQ;QAAmB,YAAO,GAAP,OAAO,CAAK;IACxK,CAAC;IAED,KAAK,CAAC,OAAqB;QACzB,OAAO,CAAC,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;aACvF,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;aAC3D,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC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CAAC;CACF;AAEM,MAAM,KAAK,GAAG,CAAI,GAAwB,EAAE,QAAW,EAAE,QAAY,EAAY,EAAE,CAAC,IAAI,KAAK,CAAI,GAAG,EAAE,QAAQ,EAAE,QAAa,CAAC,CAAC;AAAzH,QAAA,KAAK,SAAoH;AAE/H,MAAM,YAAY,GAAG,CAAI,GAAwB,EAAE,QAAW,EAAE,QAAY,EAAY,EAAE,CAAC,IAAI,KAAK,CAAI,GAAG,EAAE,QAAQ,EAAE,QAAa,CAAC;KACzI,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,8BAA8B,CAAC;KACrD,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,8BAA8B,CAAC,CACzD;AAHY,QAAA,YAAY,gBAGxB"}
@@ -1,5 +1,6 @@
1
1
  export * from './HttpMatchers';
2
2
  export * from './Match';
3
+ export * from './Check';
3
4
  export * from './ResultMatchers';
4
5
  export * from './toBeArrayOf';
5
6
  export * from './toBeArrayOfWithLength';
@@ -7,6 +8,7 @@ export * from './toBeAt';
7
8
  export * from './toBeExactlyAt';
8
9
  export * from './toFailMatcher';
9
10
  export * from './toBeValid';
11
+ export * from './toMatchArray';
10
12
  export * from './toMatchExactJson';
11
13
  export * from './toMatchException';
12
14
  export * from './toMatchJson';
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./HttpMatchers"), exports);
18
18
  __exportStar(require("./Match"), exports);
19
+ __exportStar(require("./Check"), exports);
19
20
  __exportStar(require("./ResultMatchers"), exports);
20
21
  __exportStar(require("./toBeArrayOf"), exports);
21
22
  __exportStar(require("./toBeArrayOfWithLength"), exports);
@@ -23,6 +24,7 @@ __exportStar(require("./toBeAt"), exports);
23
24
  __exportStar(require("./toBeExactlyAt"), exports);
24
25
  __exportStar(require("./toFailMatcher"), exports);
25
26
  __exportStar(require("./toBeValid"), exports);
27
+ __exportStar(require("./toMatchArray"), exports);
26
28
  __exportStar(require("./toMatchExactJson"), exports);
27
29
  __exportStar(require("./toMatchException"), exports);
28
30
  __exportStar(require("./toMatchJson"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/matchers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,0CAAwB;AACxB,mDAAiC;AACjC,gDAA8B;AAC9B,0DAAwC;AACxC,2CAAyB;AACzB,kDAAgC;AAChC,kDAAgC;AAChC,8CAA4B;AAC5B,qDAAmC;AACnC,qDAAmC;AACnC,gDAA8B;AAC9B,iDAA+B;AAC/B,gDAA8B;AAC9B,kDAAgC;AAChC,oDAAkC;AAClC,iDAA+B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/matchers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,0CAAwB;AACxB,0CAAwB;AACxB,mDAAiC;AACjC,gDAA8B;AAC9B,0DAAwC;AACxC,2CAAyB;AACzB,kDAAgC;AAChC,kDAAgC;AAChC,8CAA4B;AAC5B,iDAA+B;AAC/B,qDAAmC;AACnC,qDAAmC;AACnC,gDAA8B;AAC9B,iDAA+B;AAC/B,gDAA8B;AAC9B,kDAAgC;AAChC,oDAAkC;AAClC,iDAA+B"}
@@ -0,0 +1,9 @@
1
+ /// <reference types="jest" />
2
+ export declare function toMatchArray(this: jest.MatcherContext, received: any[], expected: any[]): jest.CustomMatcherResult;
3
+ declare global {
4
+ namespace jest {
5
+ interface Matchers<R, T> {
6
+ toMatchArray(expected: any[]): R;
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toMatchArray = void 0;
4
+ const Check_1 = require("./Check");
5
+ function toMatchArray(received, expected) {
6
+ return (0, Check_1.checkDefined)(this, received, expected)
7
+ .not(([r, e]) => r.length === e.length, ([r, e]) => `Received array has length ${r.length}, while expected array has length ${e.length}.`)
8
+ .not(([r, e]) => r.every((el, i) => this.equals(el, e[i])), "Elements in {r} do not match elements in {e}. \n\n {diff}.")
9
+ .else();
10
+ }
11
+ exports.toMatchArray = toMatchArray;
12
+ expect.extend({
13
+ toMatchArray
14
+ });
15
+ //# sourceMappingURL=toMatchArray.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toMatchArray.js","sourceRoot":"","sources":["../../src/matchers/toMatchArray.ts"],"names":[],"mappings":";;;AAAA,mCAAuC;AAEvC,SAAgB,YAAY,CAA4B,QAAe,EAAE,QAAe;IACtF,OAAO,IAAA,oBAAY,EAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,CAAC;SAC1C,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,MAAM,qCAAqC,CAAC,CAAC,MAAM,GAAG,CAAC;SACzI,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,4DAA4D,CAAC;SACxH,IAAI,EAAE,CAAC;AACZ,CAAC;AALD,oCAKC;AAED,MAAM,CAAC,MAAM,CAAC;IACZ,YAAY;CACb,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thisisagile/easy-test",
3
- "version": "15.2.0",
3
+ "version": "15.2.3",
4
4
  "description": "Straightforward library for testing microservices built with @thisisagile/easy",
5
5
  "author": "Sander Hoogendoorn",
6
6
  "license": "MIT",
@@ -0,0 +1,47 @@
1
+ import { isDefined } from "../utils/Utils";
2
+ import CustomMatcherResult = jest.CustomMatcherResult;
3
+
4
+
5
+ type ToMessage<S> = string | ((s: S[]) => string);
6
+
7
+ class Check<S> {
8
+ constructor(private ctx: jest.MatcherContext, private readonly received: S, private readonly expected: S, private readonly failed = false, private readonly message = "") {
9
+ }
10
+
11
+ print(message: ToMessage<S>): string {
12
+ return (typeof message === "function" ? message([this.received, this.expected]) : message)
13
+ .replace("{r}", this.ctx.utils.printReceived(this.received))
14
+ .replace("{e}", this.ctx.utils.printExpected(this.expected))
15
+ .replace("{diff}", this.ctx.utils.diff(this.received, this.expected) ?? "");
16
+ }
17
+
18
+ not(p: (s: (S)[]) => boolean, message: ToMessage<S>): Check<S> {
19
+ if (this.failed) {
20
+ return this;
21
+ }
22
+ try {
23
+ return new Check<S>(this.ctx, this.received, this.expected, !p([this.received, this.expected]), this.print(message));
24
+ } catch (e: any) {
25
+ return new Check<S>(this.ctx, this.received, this.expected, true, e.message);
26
+ }
27
+ }
28
+
29
+ undefined(p: (s: (S)[]) => any, message: ToMessage<S>): Check<S> {
30
+ return this.not(() => isDefined(p([this.received, this.expected])), this.print(message));
31
+ }
32
+
33
+ else(message: ToMessage<S> = "Expected {r} not to match with {e}, but it did."): CustomMatcherResult {
34
+ return {
35
+ pass: !this.failed,
36
+ message: () => (this.failed ? this.message : this.print(message))
37
+ };
38
+ }
39
+ }
40
+
41
+ export const check = <S>(ctx: jest.MatcherContext, received: S, expected?: S): Check<S> => new Check<S>(ctx, received, expected as S);
42
+
43
+ export const checkDefined = <S>(ctx: jest.MatcherContext, received: S, expected?: S): Check<S> => new Check<S>(ctx, received, expected as S)
44
+ .undefined(([r]) => r, "Received array is undefined.")
45
+ .undefined(([, e]) => e, "Expected array is undefined.")
46
+ ;
47
+
@@ -1,5 +1,6 @@
1
1
  export * from './HttpMatchers';
2
2
  export * from './Match';
3
+ export * from './Check';
3
4
  export * from './ResultMatchers';
4
5
  export * from './toBeArrayOf';
5
6
  export * from './toBeArrayOfWithLength';
@@ -7,6 +8,7 @@ export * from './toBeAt';
7
8
  export * from './toBeExactlyAt';
8
9
  export * from './toFailMatcher';
9
10
  export * from './toBeValid';
11
+ export * from './toMatchArray';
10
12
  export * from './toMatchExactJson';
11
13
  export * from './toMatchException';
12
14
  export * from './toMatchJson';
@@ -0,0 +1,21 @@
1
+ import { checkDefined } from "./Check";
2
+
3
+ export function toMatchArray(this: jest.MatcherContext, received: any[], expected: any[]) {
4
+ return checkDefined(this, received, expected)
5
+ .not(([r, e]) => r.length === e.length, ([r, e]) => `Received array has length ${r.length}, while expected array has length ${e.length}.`)
6
+ .not(([r, e]) => r.every((el, i) => this.equals(el, e[i])), "Elements in {r} do not match elements in {e}. \n\n {diff}.")
7
+ .else();
8
+ }
9
+
10
+ expect.extend({
11
+ toMatchArray
12
+ });
13
+
14
+ declare global {
15
+ // eslint-disable-next-line @typescript-eslint/no-namespace
16
+ namespace jest {
17
+ interface Matchers<R, T> {
18
+ toMatchArray(expected: any[]): R;
19
+ }
20
+ }
21
+ }