UNPKG

@uni/toast

Version:

[![npm](https://img.shields.io/npm/v/@uni/toast.svg)](https://www.npmjs.com/package/@uni/toast)

88 lines (72 loc) 2.74 kB
export var MockSelectorQueryImpl = /*#__PURE__*/function () { function MockSelectorQueryImpl(result) { this.selectorQueryContext = void 0; this.nodesRefContext = void 0; this.execResult = void 0; this.selectorQueryContext = {}; this.nodesRefContext = {}; this.setExecResult(result); this.initContext(); } var _proto = MockSelectorQueryImpl.prototype; _proto.set = function set(method, contextType, returnedType, impl) { var _this = this; var ctx = contextType === 'SelectorQuery' ? this.selectorQueryContext : this.nodesRefContext; ctx[method] = jest.fn(function () { if (impl) { impl.apply(void 0, arguments); } return returnedType === 'SelectorQuery' ? _this.selectorQueryContext : _this.nodesRefContext; }); return this.selectorQueryContext[method]; }; _proto.setExecResult = function setExecResult(result) { var _this$getMock, _this2 = this; this.execResult = result; (_this$getMock = this.getMock('exec')) == null ? void 0 : _this$getMock.mockClear(); this.set('exec', 'SelectorQuery', 'NodesRef', function (cb) { cb == null ? void 0 : cb(_this2.execResult); }); }; _proto.getMock = function getMock(method) { var res = this.selectorQueryContext[method]; if (!res) { res = this.nodesRefContext[method]; } return res; }; _proto.clearMock = function clearMock() { var _this3 = this; Object.keys(this.selectorQueryContext).forEach(function (method) { _this3.getMock(method).mockClear(); }); Object.keys(this.nodesRefContext).forEach(function (method) { _this3.getMock(method).mockClear(); }); }; _proto.clear = function clear() { this.clearMock(); this.initContext(); }; _proto.initContext = function initContext() { var _this4 = this; this.selectorQueryContext = {}; this.nodesRefContext = {}; this.set('createSelectorQuery', 'SelectorQuery', 'SelectorQuery'); this.set('in', 'SelectorQuery', 'SelectorQuery'); this.set('select', 'SelectorQuery', 'NodesRef'); this.set('selectAll', 'SelectorQuery', 'NodesRef'); this.set('selectViewport', 'SelectorQuery', 'NodesRef'); this.set('exec', 'SelectorQuery', 'NodesRef', function (cb) { cb == null ? void 0 : cb(_this4.execResult); }); this.set('boundingClientRect', 'NodesRef', 'SelectorQuery'); this.set('context', 'NodesRef', 'SelectorQuery'); this.set('getContext', 'NodesRef', 'SelectorQuery'); // bytedance this.set('fields', 'NodesRef', 'SelectorQuery'); this.set('node', 'NodesRef', 'SelectorQuery'); this.set('scrollOffset', 'NodesRef', 'SelectorQuery'); }; return MockSelectorQueryImpl; }();