UNPKG

@thisisagile/easy-test

Version:

Straightforward library for testing microservices built with @thisisagile/easy

67 lines 2.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mock = void 0; const Req_1 = require("../utils/Req"); const mockProperty = (object, getter, value) => jest.spyOn(object, getter, 'get').mockReturnValue(value); exports.mock = { clear: jest.clearAllMocks(), impl: (f) => jest.fn().mockImplementation(f), property: mockProperty, reject: (value) => jest.fn().mockRejectedValue(value), req: { id: (id) => new Req_1.Req({ id }), q: (q) => new Req_1.Req({ q }), with: (a) => new Req_1.Req(a), body: (body) => new Req_1.Req({ body }), path: (path) => new Req_1.Req({ path }), query: (query) => new Req_1.Req({ query }), }, resp: { items: (status, items = []) => ({ status: status, body: { data: { code: status.id, itemCount: items.length, items, }, }, }), errors: (status, message, errors = []) => ({ status: status, body: { error: { code: status.id, message: message, errorCount: errors.length, errors, }, }, }), }, resolve: (value) => jest.fn().mockResolvedValue(value), return: (value) => jest.fn().mockReturnValue(value), this: () => jest.fn().mockReturnThis(), provider: { data: (...items) => ({ execute: jest.fn().mockResolvedValue({ body: { data: { itemCount: items.length, items, }, }, }), }), }, empty: (props = {}) => props, date: (epoch = 1621347575) => { const date = new Date(epoch); date.toString = exports.mock.return('Mon Jan 19 1970 19:22:27 GMT+0100 (Central European Standard Time)'); date.toLocaleDateString = exports.mock.return('19/01/1970'); date.toDateString = exports.mock.return('19/01/1970'); return date; }, once: (...values) => values.reduce((m, v) => m.mockImplementationOnce(() => v), jest.fn()), }; //# sourceMappingURL=Mock.js.map