UNPKG

@thisisagile/easy-test

Version:

Straightforward library for testing microservices built with @thisisagile/easy

86 lines (85 loc) 2.47 kB
import { Req } from "../chunk-SJR3TRWF.mjs"; import "../chunk-O475TEG2.mjs"; // src/mock/Mocks.ts var Mocks = class { req = { id: (id) => new Req({ id }), q: (q) => new Req({ q }), with: (a) => new Req(a), body: (body) => new Req({ body }), path: (path) => new Req({ path }), query: (query) => new Req({ query }) }; resp = { items: (status, items = []) => ({ status, body: { data: { code: status.id, itemCount: items.length, items } } }), errors: (status, message, errors = []) => ({ status, body: { error: { code: status.id, message, errorCount: errors.length, errors } } }) }; provider = { data: (...items) => ({ execute: jest.fn().mockResolvedValue({ body: { data: { itemCount: items.length, items } } }) }) }; static getArg = (mock2, call = 0, arg = 0) => { if (!isJestMock(mock2)) throw new Error("Function provided is not a Jest mock"); return mock2.mock.calls[call]?.[arg]; }; clear = () => jest.clearAllMocks(); impl = (f) => jest.fn().mockImplementation(f); property = (object, getter, value) => jest.spyOn(object, getter, "get").mockReturnValue(value); reject = (value) => jest.fn().mockRejectedValue(value); rejectWith = (props = {}) => jest.fn().mockRejectedValue(mock.a(props)); resolve = (value) => jest.fn().mockResolvedValue(value); resolveWith = (props = {}) => jest.fn().mockResolvedValue(mock.a(props)); return = (value) => jest.fn().mockReturnValue(value); returnWith = (props = {}) => jest.fn().mockReturnValue(mock.a(props)); this = () => jest.fn().mockReturnThis(); empty = (props = {}) => props; a = this.empty; an = this.empty; date = (epoch = 1621347575) => { const date = new Date(epoch); date.toString = mock.return("Mon Jan 19 1970 19:22:27 GMT+0100 (Central European Standard Time)"); date.toLocaleDateString = mock.return("19/01/1970"); date.toDateString = mock.return("19/01/1970"); return date; }; once = (...values) => values.reduce((m, v) => m.mockImplementationOnce(() => v), jest.fn()); }; function isJestMock(fn) { return typeof fn === "function" && "mock" in fn && Array.isArray(fn.mock?.calls); } var mock = new Mocks(); export { Mocks, mock }; //# sourceMappingURL=Mocks.mjs.map