UNPKG

reshow-flux

Version:
105 lines (103 loc) 3.6 kB
import _classCallCheck from "reshow-runtime/es/helpers/classCallCheck"; import _createClass from "reshow-runtime/es/helpers/createClass"; import _possibleConstructorReturn from "reshow-runtime/es/helpers/possibleConstructorReturn"; import _isNativeReflectConstruct from "reshow-runtime/es/helpers/isNativeReflectConstruct"; import _getPrototypeOf from "reshow-runtime/es/helpers/getPrototypeOf"; import _inherits from "reshow-runtime/es/helpers/inherits"; import _defineProperty from "reshow-runtime/es/helpers/defineProperty"; import _objectSpread from "reshow-runtime/es/helpers/objectSpread2"; import _objectWithoutProperties from "reshow-runtime/es/helpers/objectWithoutProperties"; import _asyncToGenerator from "reshow-runtime/es/helpers/asyncToGenerator"; var _excluded = ["storeLocator"]; function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } // @ts-check import * as React from "react"; var { Component } = React; import { createReducer } from "reshow-flux-base"; import { expect } from "chai"; import { act, render, screen } from "reshow-unit"; import callfunc from "call-func"; import useConnect from "../useConnect.mjs"; import { jsx as _jsx } from "react/jsx-runtime"; describe("Connect Hook (clean Props)", function () { var reducer; beforeEach(function () { reducer = createReducer(function (_state, action) { return action; }, {}); }); it("test clean props", /*#__PURE__*/_asyncToGenerator(function* () { var [store] = reducer; var Foo = function Foo(/**@type any*/props) { var state = useConnect({ storeLocator: function storeLocator() { return store; }, calculateState: function calculateState() { return store.getState(); } })(props); var { storeLocator } = props, otherProps = _objectWithoutProperties(props, _excluded); return /*#__PURE__*/_jsx("div", _objectSpread({ role: "udom" }, _objectSpread(_objectSpread({}, otherProps), state))); }; /** * @type any */ var setState = { current: null }; var Bar = /*#__PURE__*/function (_Component) { function Bar(/**@type any*/props) { var _this; _classCallCheck(this, Bar); _this = _callSuper(this, Bar, [props]); _defineProperty(_this, "state", { /** * @type any */ p: null }); setState.current = function () { for (var _len = arguments.length, p = new Array(_len), _key = 0; _key < _len; _key++) { p[_key] = arguments[_key]; } // @ts-ignore callfunc(_this.setState, p, _this); }; return _this; } _inherits(Bar, _Component); return _createClass(Bar, [{ key: "render", value: function render() { return /*#__PURE__*/_jsx(Foo, _objectSpread({}, this.state.p)); } }]); }(Component); render(/*#__PURE__*/_jsx(Bar, {})); yield act(function () { setState.current({ p: { foo: "a", bar: "b" } }); }, 5); expect(screen().getByRole("udom").outerHTML).to.equal('<div role="udom" foo="a" bar="b"></div>'); yield act(function () { setState.current({ p: { bar: "c" } }); }, 5); expect(screen().getByRole("udom").outerHTML).to.equal('<div role="udom" bar="c"></div>'); })); });