@thisisagile/easy-test 21.2.2 → 21.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.
package/dist/index.d.ts CHANGED
@@ -19,6 +19,6 @@ import { toBeQueriedWith } from "./matchers/toBeQueriedWith.js";
19
19
  import { toBeRoutedTo, toMatchAsString, weExpectedButReceivedInstead } from "./matchers/toBeRoutedTo.js";
20
20
  import "./matchers/index.js";
21
21
  import { ObjectContainingJson, ObjectContainingText, ObjectContainingTextExact, fits } from "./mock/Fits.js";
22
- import { Mocks, mock } from "./mock/Mocks.js";
22
+ import { AnyMock, Mocks, mock } from "./mock/Mocks.js";
23
23
  import "./mock/index.js";
24
- export { Fails, FailsWith, Match, MatchesExactJson, MatchesJson, Mocks, ObjectContainingJson, ObjectContainingText, ObjectContainingTextExact, Passes, PassesWith, check, checkDefined, fits, match, mock, 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 };
24
+ export { AnyMock, Fails, FailsWith, Match, MatchesExactJson, MatchesJson, Mocks, ObjectContainingJson, ObjectContainingText, ObjectContainingTextExact, Passes, PassesWith, check, checkDefined, fits, match, mock, 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,6 +1,10 @@
1
1
  import { Id, Json } from "../utils/Types.js";
2
2
  import { Req } from "../utils/Req.js";
3
3
  import { HttpStatus, Response } from "../utils/Response.js";
4
+ import { jest } from "@jest/globals";
5
+ import { PropertyLikeKeys } from "jest-mock";
6
+ type AnyFunction = (...args: any[]) => any;
7
+ export type AnyMock = jest.Mock<AnyFunction>;
4
8
  export declare class Mocks {
5
9
  req: {
6
10
  id: (id: Id) => Req;
@@ -16,25 +20,26 @@ export declare class Mocks {
16
20
  };
17
21
  provider: {
18
22
  data: (...items: any[]) => {
19
- execute: jest.Mock;
23
+ execute: AnyMock;
20
24
  };
21
25
  };
22
26
  static readonly getArg: <T>(mock: unknown, call?: number, arg?: number) => T | undefined;
23
27
  clear: () => typeof jest;
24
- impl: (f?: (...args: any[]) => any) => jest.Mock;
25
- property: <T extends object, P extends jest.NonFunctionPropertyNames<Required<T>>>(object: T, getter: P, value: T[P]) => jest.SpyInstance;
26
- reject: (value?: unknown) => jest.Mock;
27
- rejectWith: <T = any>(props?: Partial<T>) => jest.Mock;
28
- resolve: (value?: unknown) => jest.Mock;
29
- resolveWith: <T = any>(props?: Partial<T>) => jest.Mock;
30
- return: (value?: unknown) => jest.Mock;
31
- returnWith: <T = any>(props?: Partial<T>) => jest.Mock;
32
- this: () => jest.Mock;
28
+ impl: (f?: AnyFunction) => AnyMock;
29
+ property: <T extends object, P extends PropertyLikeKeys<T>>(object: T, getter: P, value: Required<T>[P]) => jest.SpiedGetter<Required<T>[P]>;
30
+ reject: (value?: unknown) => AnyMock;
31
+ rejectWith: <T = any>(props?: Partial<T>) => AnyMock;
32
+ resolve: (value?: unknown) => AnyMock;
33
+ resolveWith: <T = any>(props?: Partial<T>) => AnyMock;
34
+ return: (value?: unknown) => AnyMock;
35
+ returnWith: <T = any>(props?: Partial<T>) => AnyMock;
36
+ this: () => AnyMock;
33
37
  empty: <T = any>(props?: Partial<T>) => T;
34
38
  a: <T = any>(props?: Partial<T>) => T;
35
39
  an: <T = any>(props?: Partial<T>) => T;
36
40
  date: (epoch?: number) => Date;
37
- once: (...values: unknown[]) => jest.Mock;
41
+ once: (...values: unknown[]) => AnyMock;
38
42
  }
39
43
  export declare const mock: Mocks;
44
+ export {};
40
45
  //# sourceMappingURL=Mocks.d.ts.map
@@ -1,4 +1,5 @@
1
1
  import { Req } from "../utils/Req.js";
2
+ import { jest } from "@jest/globals";
2
3
  // src/mock/Mocks.ts
3
4
  var Mocks = class {
4
5
  req = {
@@ -37,7 +38,7 @@ var Mocks = class {
37
38
  return mock.mock.calls[call]?.[arg];
38
39
  };
39
40
  clear = () => jest.clearAllMocks();
40
- impl = (f) => jest.fn().mockImplementation(f);
41
+ impl = (f) => jest.fn(f);
41
42
  property = (object, getter, value) => jest.spyOn(object, getter, "get").mockReturnValue(value);
42
43
  reject = (value) => jest.fn().mockRejectedValue(value);
43
44
  rejectWith = (props = {}) => jest.fn().mockRejectedValue(mock.a(props));
@@ -1 +1 @@
1
- {"version":3,"file":"Mocks.js","names":[],"sources":["../../src/mock/Mocks.ts"],"sourcesContent":["import { Id, Json } from '../utils/Types';\nimport { Req } from '../utils/Req';\nimport { HttpStatus, Response } from '../utils/Response';\n\nexport class Mocks {\n req = {\n id: (id: Id): Req => new Req({ id }),\n q: (q: unknown): Req => new Req({ q }),\n with: (a: Json): Req => new Req(a),\n body: <B = unknown>(body: B): Req<B> => new Req<B>({ body }),\n path: (path: Json): Req => new Req({ path }),\n query: (query: Json): Req => new Req({ query }),\n };\n resp = {\n items: (status: HttpStatus, items: unknown[] = []): Response => ({\n status: status,\n body: {\n data: {\n code: status.id as number,\n itemCount: items.length,\n items,\n },\n },\n }),\n errors: (status: HttpStatus, message: string, errors: unknown[] = []): Response => ({\n status: status,\n body: {\n error: {\n code: status.id as number,\n message: message,\n errorCount: errors.length,\n errors,\n },\n },\n }),\n };\n provider = {\n data: (...items: any[]): { execute: jest.Mock } => ({\n execute: jest.fn().mockResolvedValue({\n body: {\n data: {\n itemCount: items.length,\n items,\n },\n },\n }),\n }),\n };\n\n static readonly getArg = <T>(mock: unknown, call = 0, arg = 0): T | undefined => {\n if (!isJestMock(mock)) throw new Error('Function provided is not a Jest mock');\n return mock.mock.calls[call]?.[arg] as T;\n };\n\n clear = (): typeof jest => jest.clearAllMocks();\n\n impl = (f?: (...args: any[]) => any): jest.Mock => jest.fn().mockImplementation(f);\n\n property = <T extends object, P extends jest.NonFunctionPropertyNames<Required<T>>>(object: T, getter: P, value: T[P]): jest.SpyInstance =>\n jest.spyOn(object, getter, 'get' as jest.PropertyAccessors<P, T>).mockReturnValue(value as any);\n\n reject = (value?: unknown): jest.Mock => jest.fn().mockRejectedValue(value);\n\n rejectWith = <T = any>(props: Partial<T> = {}): jest.Mock => jest.fn().mockRejectedValue(mock.a(props));\n\n resolve = (value?: unknown): jest.Mock => jest.fn().mockResolvedValue(value);\n\n resolveWith = <T = any>(props: Partial<T> = {}): jest.Mock => jest.fn().mockResolvedValue(mock.a(props));\n\n return = (value?: unknown): jest.Mock => jest.fn().mockReturnValue(value);\n\n returnWith = <T = any>(props: Partial<T> = {}): jest.Mock => jest.fn().mockReturnValue(mock.a(props));\n\n this = (): jest.Mock => jest.fn().mockReturnThis();\n\n empty = <T = any>(props: Partial<T> = {}): T => props as T;\n a = this.empty;\n an = this.empty;\n date = (epoch = 1621347575): Date => {\n const date = new Date(epoch);\n date.toString = mock.return('Mon Jan 19 1970 19:22:27 GMT+0100 (Central European Standard Time)');\n date.toLocaleDateString = mock.return('19/01/1970');\n date.toDateString = mock.return('19/01/1970');\n return date;\n };\n once = (...values: unknown[]): jest.Mock => values.reduce((m: jest.Mock, v: unknown) => m.mockImplementationOnce(() => v), jest.fn());\n}\n\nfunction isJestMock(fn: any): fn is jest.Mock {\n return typeof fn === 'function' && 'mock' in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,cAAuB,QAAoB,CAAC,MAAiB,KAAK,GAAG,CAAC,CAAC,kBAAkB,KAAK,EAAE,KAAK,CAAC;CAEtG,WAAW,UAA+B,KAAK,GAAG,CAAC,CAAC,kBAAkB,KAAK;CAE3E,eAAwB,QAAoB,CAAC,MAAiB,KAAK,GAAG,CAAC,CAAC,kBAAkB,KAAK,EAAE,KAAK,CAAC;CAEvG,UAAU,UAA+B,KAAK,GAAG,CAAC,CAAC,gBAAgB,KAAK;CAExE,cAAuB,QAAoB,CAAC,MAAiB,KAAK,GAAG,CAAC,CAAC,gBAAgB,KAAK,EAAE,KAAK,CAAC;CAEpG,aAAwB,KAAK,GAAG,CAAC,CAAC,eAAe;CAEjD,SAAkB,QAAoB,CAAC,MAAS;CAChD,IAAI,KAAK;CACT,KAAK,KAAK;CACV,QAAQ,QAAQ,eAAqB;EACnC,MAAM,OAAO,IAAI,KAAK,KAAK;EAC3B,KAAK,WAAW,KAAK,OAAO,oEAAoE;EAChG,KAAK,qBAAqB,KAAK,OAAO,YAAY;EAClD,KAAK,eAAe,KAAK,OAAO,YAAY;EAC5C,OAAO;CACT;CACA,QAAQ,GAAG,WAAiC,OAAO,QAAQ,GAAc,MAAe,EAAE,6BAA6B,CAAC,GAAG,KAAK,GAAG,CAAC;AACtI;AAEA,SAAS,WAAW,IAA0B;CAC5C,OAAO,OAAO,OAAO,cAAc,UAAU,MAAM,MAAM,QAAQ,GAAG,MAAM,KAAK;AACjF;AAEA,MAAa,OAAO,IAAI,MAAM"}
1
+ {"version":3,"file":"Mocks.js","names":[],"sources":["../../src/mock/Mocks.ts"],"sourcesContent":["import { jest } from '@jest/globals';\nimport type { PropertyLikeKeys } from 'jest-mock';\nimport { Id, Json } from '../utils/Types';\nimport { Req } from '../utils/Req';\nimport { HttpStatus, Response } from '../utils/Response';\n\ntype AnyFunction = (...args: any[]) => any;\nexport type AnyMock = jest.Mock<AnyFunction>;\n\nexport class Mocks {\n req = {\n id: (id: Id): Req => new Req({ id }),\n q: (q: unknown): Req => new Req({ q }),\n with: (a: Json): Req => new Req(a),\n body: <B = unknown>(body: B): Req<B> => new Req<B>({ body }),\n path: (path: Json): Req => new Req({ path }),\n query: (query: Json): Req => new Req({ query }),\n };\n resp = {\n items: (status: HttpStatus, items: unknown[] = []): Response => ({\n status: status,\n body: {\n data: {\n code: status.id as number,\n itemCount: items.length,\n items,\n },\n },\n }),\n errors: (status: HttpStatus, message: string, errors: unknown[] = []): Response => ({\n status: status,\n body: {\n error: {\n code: status.id as number,\n message: message,\n errorCount: errors.length,\n errors,\n },\n },\n }),\n };\n provider = {\n data: (...items: any[]): { execute: AnyMock } => ({\n execute: jest.fn<AnyFunction>().mockResolvedValue({\n body: {\n data: {\n itemCount: items.length,\n items,\n },\n },\n }),\n }),\n };\n\n static readonly getArg = <T>(mock: unknown, call = 0, arg = 0): T | undefined => {\n if (!isJestMock(mock)) throw new Error('Function provided is not a Jest mock');\n return mock.mock.calls[call]?.[arg] as T;\n };\n\n clear = (): typeof jest => jest.clearAllMocks();\n\n impl = (f?: AnyFunction): AnyMock => jest.fn<AnyFunction>(f);\n\n property = <T extends object, P extends PropertyLikeKeys<T>>(object: T, getter: P, value: Required<T>[P]): jest.SpiedGetter<Required<T>[P]> =>\n jest.spyOn(object, getter, 'get').mockReturnValue(value);\n\n reject = (value?: unknown): AnyMock => jest.fn<AnyFunction>().mockRejectedValue(value);\n\n rejectWith = <T = any>(props: Partial<T> = {}): AnyMock => jest.fn<AnyFunction>().mockRejectedValue(mock.a(props));\n\n resolve = (value?: unknown): AnyMock => jest.fn<AnyFunction>().mockResolvedValue(value);\n\n resolveWith = <T = any>(props: Partial<T> = {}): AnyMock => jest.fn<AnyFunction>().mockResolvedValue(mock.a(props));\n\n return = (value?: unknown): AnyMock => jest.fn<AnyFunction>().mockReturnValue(value);\n\n returnWith = <T = any>(props: Partial<T> = {}): AnyMock => jest.fn<AnyFunction>().mockReturnValue(mock.a(props));\n\n this = (): AnyMock => jest.fn<AnyFunction>().mockReturnThis();\n\n empty = <T = any>(props: Partial<T> = {}): T => props as T;\n a = this.empty;\n an = this.empty;\n date = (epoch = 1621347575): Date => {\n const date = new Date(epoch);\n date.toString = mock.return('Mon Jan 19 1970 19:22:27 GMT+0100 (Central European Standard Time)');\n date.toLocaleDateString = mock.return('19/01/1970');\n date.toDateString = mock.return('19/01/1970');\n return date;\n };\n once = (...values: unknown[]): AnyMock => values.reduce((m: AnyMock, v: unknown) => m.mockImplementationOnce(() => v), jest.fn<AnyFunction>());\n}\n\nfunction isJestMock(fn: any): fn is AnyMock {\n return typeof fn === 'function' && 'mock' in fn && Array.isArray(fn.mock?.calls);\n}\n\nexport const mock = new Mocks();\n"],"mappings":";;;AASA,IAAa,QAAb,MAAmB;CACjB,MAAM;EACJ,KAAK,OAAgB,IAAI,IAAI,EAAE,GAAG,CAAC;EACnC,IAAI,MAAoB,IAAI,IAAI,EAAE,EAAE,CAAC;EACrC,OAAO,MAAiB,IAAI,IAAI,CAAC;EACjC,OAAoB,SAAoB,IAAI,IAAO,EAAE,KAAK,CAAC;EAC3D,OAAO,SAAoB,IAAI,IAAI,EAAE,KAAK,CAAC;EAC3C,QAAQ,UAAqB,IAAI,IAAI,EAAE,MAAM,CAAC;CAChD;CACA,OAAO;EACL,QAAQ,QAAoB,QAAmB,CAAC,OAAiB;GACvD;GACR,MAAM,EACJ,MAAM;IACJ,MAAM,OAAO;IACb,WAAW,MAAM;IACjB;GACF,EACF;EACF;EACA,SAAS,QAAoB,SAAiB,SAAoB,CAAC,OAAiB;GAC1E;GACR,MAAM,EACJ,OAAO;IACL,MAAM,OAAO;IACJ;IACT,YAAY,OAAO;IACnB;GACF,EACF;EACF;CACF;CACA,WAAW,EACT,OAAO,GAAG,WAAwC,EAChD,SAAS,KAAK,GAAgB,CAAC,CAAC,kBAAkB,EAChD,MAAM,EACJ,MAAM;EACJ,WAAW,MAAM;EACjB;CACF,EACF,EACF,CAAC,EACH,GACF;CAEA,OAAgB,UAAa,MAAe,OAAO,GA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,GAAG,MAAM,KAAK;AACjF;AAEA,MAAa,OAAO,IAAI,MAAM"}
@@ -1,3 +1,3 @@
1
1
  import { ObjectContainingJson, ObjectContainingText, ObjectContainingTextExact, fits } from "./Fits.js";
2
- import { Mocks, mock } from "./Mocks.js";
3
- export { Mocks, ObjectContainingJson, ObjectContainingText, ObjectContainingTextExact, fits, mock };
2
+ import { AnyMock, Mocks, mock } from "./Mocks.js";
3
+ export { AnyMock, Mocks, ObjectContainingJson, ObjectContainingText, ObjectContainingTextExact, fits, mock };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thisisagile/easy-test",
3
- "version": "21.2.2",
3
+ "version": "21.2.3",
4
4
  "description": "Straightforward library for testing microservices built with @thisisagile/easy",
5
5
  "author": "Sander Hoogendoorn",
6
6
  "license": "MIT",
@@ -49,11 +49,13 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "@jest/expect-utils": "^30.5.2",
52
+ "@jest/globals": "^30.5.2",
52
53
  "@types/jest": "^30.0.0",
53
54
  "@types/node": "^26.6.6",
54
55
  "expect": "^30.5.2",
55
56
  "jest": "^30.5.2",
56
57
  "jest-junit": "^17.0.0",
58
+ "jest-mock": "^30.5.2",
57
59
  "jest-sonar-reporter": "^2.0.0",
58
60
  "ts-jest": "^29.4.15"
59
61
  },
package/src/mock/Mocks.ts CHANGED
@@ -1,7 +1,12 @@
1
+ import { jest } from '@jest/globals';
2
+ import type { PropertyLikeKeys } from 'jest-mock';
1
3
  import { Id, Json } from '../utils/Types';
2
4
  import { Req } from '../utils/Req';
3
5
  import { HttpStatus, Response } from '../utils/Response';
4
6
 
7
+ type AnyFunction = (...args: any[]) => any;
8
+ export type AnyMock = jest.Mock<AnyFunction>;
9
+
5
10
  export class Mocks {
6
11
  req = {
7
12
  id: (id: Id): Req => new Req({ id }),
@@ -35,8 +40,8 @@ export class Mocks {
35
40
  }),
36
41
  };
37
42
  provider = {
38
- data: (...items: any[]): { execute: jest.Mock } => ({
39
- execute: jest.fn().mockResolvedValue({
43
+ data: (...items: any[]): { execute: AnyMock } => ({
44
+ execute: jest.fn<AnyFunction>().mockResolvedValue({
40
45
  body: {
41
46
  data: {
42
47
  itemCount: items.length,
@@ -54,24 +59,24 @@ export class Mocks {
54
59
 
55
60
  clear = (): typeof jest => jest.clearAllMocks();
56
61
 
57
- impl = (f?: (...args: any[]) => any): jest.Mock => jest.fn().mockImplementation(f);
62
+ impl = (f?: AnyFunction): AnyMock => jest.fn<AnyFunction>(f);
58
63
 
59
- property = <T extends object, P extends jest.NonFunctionPropertyNames<Required<T>>>(object: T, getter: P, value: T[P]): jest.SpyInstance =>
60
- jest.spyOn(object, getter, 'get' as jest.PropertyAccessors<P, T>).mockReturnValue(value as any);
64
+ property = <T extends object, P extends PropertyLikeKeys<T>>(object: T, getter: P, value: Required<T>[P]): jest.SpiedGetter<Required<T>[P]> =>
65
+ jest.spyOn(object, getter, 'get').mockReturnValue(value);
61
66
 
62
- reject = (value?: unknown): jest.Mock => jest.fn().mockRejectedValue(value);
67
+ reject = (value?: unknown): AnyMock => jest.fn<AnyFunction>().mockRejectedValue(value);
63
68
 
64
- rejectWith = <T = any>(props: Partial<T> = {}): jest.Mock => jest.fn().mockRejectedValue(mock.a(props));
69
+ rejectWith = <T = any>(props: Partial<T> = {}): AnyMock => jest.fn<AnyFunction>().mockRejectedValue(mock.a(props));
65
70
 
66
- resolve = (value?: unknown): jest.Mock => jest.fn().mockResolvedValue(value);
71
+ resolve = (value?: unknown): AnyMock => jest.fn<AnyFunction>().mockResolvedValue(value);
67
72
 
68
- resolveWith = <T = any>(props: Partial<T> = {}): jest.Mock => jest.fn().mockResolvedValue(mock.a(props));
73
+ resolveWith = <T = any>(props: Partial<T> = {}): AnyMock => jest.fn<AnyFunction>().mockResolvedValue(mock.a(props));
69
74
 
70
- return = (value?: unknown): jest.Mock => jest.fn().mockReturnValue(value);
75
+ return = (value?: unknown): AnyMock => jest.fn<AnyFunction>().mockReturnValue(value);
71
76
 
72
- returnWith = <T = any>(props: Partial<T> = {}): jest.Mock => jest.fn().mockReturnValue(mock.a(props));
77
+ returnWith = <T = any>(props: Partial<T> = {}): AnyMock => jest.fn<AnyFunction>().mockReturnValue(mock.a(props));
73
78
 
74
- this = (): jest.Mock => jest.fn().mockReturnThis();
79
+ this = (): AnyMock => jest.fn<AnyFunction>().mockReturnThis();
75
80
 
76
81
  empty = <T = any>(props: Partial<T> = {}): T => props as T;
77
82
  a = this.empty;
@@ -83,10 +88,10 @@ export class Mocks {
83
88
  date.toDateString = mock.return('19/01/1970');
84
89
  return date;
85
90
  };
86
- once = (...values: unknown[]): jest.Mock => values.reduce((m: jest.Mock, v: unknown) => m.mockImplementationOnce(() => v), jest.fn());
91
+ once = (...values: unknown[]): AnyMock => values.reduce((m: AnyMock, v: unknown) => m.mockImplementationOnce(() => v), jest.fn<AnyFunction>());
87
92
  }
88
93
 
89
- function isJestMock(fn: any): fn is jest.Mock {
94
+ function isJestMock(fn: any): fn is AnyMock {
90
95
  return typeof fn === 'function' && 'mock' in fn && Array.isArray(fn.mock?.calls);
91
96
  }
92
97