UNPKG

@gravity-ui/data-source

Version:
70 lines (69 loc) 3.13 kB
"use strict"; var _regeneratorRuntime2 = _interopRequireDefault(require("@babel/runtime/helpers/regeneratorRuntime")); var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); var _skipContext = require("../skipContext"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } 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 = (0, _skipContext.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 = (0, _skipContext.skipContext)(mockFn); var result = wrappedFn('context', 'queryFnContext'); expect(mockFn).toHaveBeenCalledWith(); expect(result).toBe('result'); }); it('should work with async functions', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/(0, _regeneratorRuntime2.default)().mark(function _callee2() { var mockFn, wrappedFn, result; return (0, _regeneratorRuntime2.default)().wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: mockFn = jest.fn(/*#__PURE__*/function () { var _ref2 = (0, _asyncToGenerator2.default)(/*#__PURE__*/(0, _regeneratorRuntime2.default)().mark(function _callee(arg) { return (0, _regeneratorRuntime2.default)().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 = (0, _skipContext.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 = (0, _skipContext.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