UNPKG

reshow-unit

Version:
95 lines 3.31 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"; var _div, _div2, _div3, _div4, _div5; function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } import { PureComponent } from "react"; import { expect } from "chai"; import { render, getRoleHtml } from "../index.mjs"; import { jsx as _jsx } from "react/jsx-runtime"; describe("Test Render", function () { it("basic test", function () { var Foo = function Foo(props) { return _div || (_div = /*#__PURE__*/_jsx("div", { children: "bar" })); }; var wrap = render(/*#__PURE__*/_jsx(Foo, {})); expect(wrap.html()).to.equal("<div>bar</div>"); }); it("test unmount", function () { var Foo = function Foo(props) { return _div2 || (_div2 = /*#__PURE__*/_jsx("div", { children: "bar" })); }; var wrap = render(/*#__PURE__*/_jsx(Foo, {})); expect(document.body.innerHTML).to.have.string("bar"); wrap.unmount(); expect(document.body.innerHTML).not.have.string("bar"); }); it("Test get role html", function () { var Foo = function Foo(props) { return _div3 || (_div3 = /*#__PURE__*/_jsx("div", { role: "dom", children: "bar" })); }; render(/*#__PURE__*/_jsx(Foo, {})); expect(getRoleHtml("dom")).to.equal("<div role=\"dom\">bar</div>"); }); it("Test get instance", function () { var Foo = /*#__PURE__*/function (_PureComponent) { function Foo() { _classCallCheck(this, Foo); return _callSuper(this, Foo, arguments); } _inherits(Foo, _PureComponent); return _createClass(Foo, [{ key: "bar", value: function bar() { return "foo"; } }, { key: "render", value: function render() { return _div4 || (_div4 = /*#__PURE__*/_jsx("div", {})); } }]); }(PureComponent); var wrap = render(/*#__PURE__*/_jsx(Foo, {}), { instance: true }); expect(wrap.instance().bar()).to.equal("foo"); }); it("Test get instance with callback", function () { var Foo = /*#__PURE__*/function (_PureComponent2) { function Foo() { _classCallCheck(this, Foo); return _callSuper(this, Foo, arguments); } _inherits(Foo, _PureComponent2); return _createClass(Foo, [{ key: "bar", value: function bar() { return "foo"; } }, { key: "render", value: function render() { return _div5 || (_div5 = /*#__PURE__*/_jsx("div", {})); } }]); }(PureComponent); var myEl; var wrap = render(/*#__PURE__*/_jsx(Foo, {}), { instance: function instance(el) { return myEl = el; } }); expect(myEl.bar()).to.equal("foo"); }); });