UNPKG

reshow-flux

Version:
88 lines 3.21 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 _asyncToGenerator from "reshow-runtime/es/helpers/asyncToGenerator"; 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 { PureComponent } = React; import { expect } from "chai"; import { render, act } from "reshow-unit"; import * as sinon from "sinon"; import { createReducer } from "reshow-flux-base"; import useConnect from "../useConnect.mjs"; import { jsx as _jsx } from "react/jsx-runtime"; describe("useConnect Unmount Test", function () { var sandbox = sinon.createSandbox(); var reducer; beforeEach(function () { reducer = createReducer(function (_state, action) { return action; }, {}); }); afterEach(function () { sandbox.restore(); }); it("basic test", /*#__PURE__*/_asyncToGenerator(function* () { var _Foo; var [store, dispatch] = reducer; var Foo = function Foo(/**@type any*/props) { var state = useConnect({ storeLocator: function storeLocator() { return store; }, calculateState: function calculateState() { return store.getState(); } })(props); return /*#__PURE__*/_jsx("div", { className: state.foo }); }; var oFake = {}; var FakeComponent = /*#__PURE__*/function (_PureComponent) { function FakeComponent(/**@type any*/props) { var _this; _classCallCheck(this, FakeComponent); _this = _callSuper(this, FakeComponent, [props]); _defineProperty(_this, "state", { show: true }); oFake.set = function (/**@type any*/k, /**@type any*/v) { // @ts-ignore _this.setState({ [k]: v }); }; return _this; } _inherits(FakeComponent, _PureComponent); return _createClass(FakeComponent, [{ key: "render", value: function render() { if (this.state.show) { return _Foo || (_Foo = /*#__PURE__*/_jsx(Foo, {})); } else { return null; } } }]); }(PureComponent); render(/*#__PURE__*/_jsx(FakeComponent, {})); sandbox.spy(store, "removeListener"); console.log("before unmount", store.removeListener.callCount); expect(store.removeListener.callCount).to.equal(0); yield act(function () { return oFake.set("show", false); }); expect(store.removeListener.callCount).to.equal(1); console.log("after unmount", store.removeListener.callCount); dispatch({}); })); });