UNPKG

@gravity-ui/data-source

Version:
67 lines 2.81 kB
import _regeneratorRuntime from "@babel/runtime/helpers/regeneratorRuntime"; import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import { skipContext } from '../skipContext'; describe('skipContext', function () { it('should ignore context and query function context parameters', function () { var mockFn = jest.fn(function (arg1, arg2) { return "".concat(arg1, "-").concat(arg2); }); var wrappedFn = skipContext(mockFn); var result = wrappedFn('context', 'queryFnContext', 'hello', 42); expect(mockFn).toHaveBeenCalledWith('hello', 42); expect(result).toBe('hello-42'); }); it('should work with functions that have no parameters', function () { var mockFn = jest.fn(function () { return 'result'; }); var wrappedFn = skipContext(mockFn); var result = wrappedFn('context', 'queryFnContext'); expect(mockFn).toHaveBeenCalledWith(); expect(result).toBe('result'); }); it('should work with async functions', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() { var mockFn, wrappedFn, result; return _regeneratorRuntime().wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: mockFn = jest.fn(/*#__PURE__*/function () { var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(arg) { return _regeneratorRuntime().wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: return _context.abrupt("return", "async-".concat(arg)); case 1: case "end": return _context.stop(); } }, _callee); })); return function (_x) { return _ref2.apply(this, arguments); }; }()); wrappedFn = skipContext(mockFn); _context2.next = 4; return wrappedFn('context', 'queryFnContext', 'test'); case 4: result = _context2.sent; expect(mockFn).toHaveBeenCalledWith('test'); expect(result).toBe('async-test'); case 7: case "end": return _context2.stop(); } }, _callee2); }))); it('should pass multiple arguments correctly', function () { var mockFn = jest.fn(function (arg1, arg2, arg3) { return "".concat(arg1, "-").concat(arg2, "-").concat(arg3); }); var wrappedFn = skipContext(mockFn); var result = wrappedFn('context', 'queryFnContext', 'hello', 42, true); expect(mockFn).toHaveBeenCalledWith('hello', 42, true); expect(result).toBe('hello-42-true'); }); }); // #sourceMappingURL=skipContext.test.js.map