reshow-hooks
Advanced tools
Comparing version 0.16.0 to 0.17.0
@@ -5,4 +5,2 @@ "use strict"; | ||
var _react = _interopRequireDefault(require("react")); | ||
var _chai = require("chai"); | ||
@@ -14,2 +12,4 @@ | ||
var _jsxRuntime = require("react/jsx-runtime"); | ||
describe("test useMounted", function () { | ||
@@ -27,7 +27,7 @@ afterEach(function () { | ||
var wrap = (0, _reshowUnit.mount)( /*#__PURE__*/_react["default"].createElement(Foo, null)); | ||
(0, _reshowUnit.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Foo, {})); | ||
(0, _chai.expect)(hackGlobal()).to.be["true"]; | ||
wrap.unmount(); | ||
(0, _reshowUnit.unmount)(); | ||
(0, _chai.expect)(hackGlobal()).to.be["false"]; | ||
}); | ||
}); |
"use strict"; | ||
var _interopRequireWildcard = require("reshow-runtime/helpers/interopRequireWildcard"); | ||
var _interopRequireDefault = require("reshow-runtime/helpers/interopRequireDefault"); | ||
var _regenerator = _interopRequireDefault(require("reshow-runtime/regenerator")); | ||
var _classCallCheck2 = _interopRequireDefault(require("reshow-runtime/helpers/classCallCheck")); | ||
@@ -19,4 +19,6 @@ | ||
var _react = _interopRequireWildcard(require("react")); | ||
var _asyncToGenerator2 = _interopRequireDefault(require("reshow-runtime/helpers/asyncToGenerator")); | ||
var _react = require("react"); | ||
var _chai = require("chai"); | ||
@@ -28,69 +30,81 @@ | ||
var _jsxRuntime = require("react/jsx-runtime"); | ||
describe("test usePrevious", function () { | ||
it("basic test", function () { | ||
var hackGlobal; | ||
it("basic test", /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() { | ||
var hackGlobal, Foo, ufakeSet, Comp; | ||
return _regenerator["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
Foo = function Foo(props) { | ||
var prev = (0, _usePrevious["default"])(props.v); | ||
var Foo = function Foo(props) { | ||
var prev = (0, _usePrevious["default"])(props.v); | ||
hackGlobal = function hackGlobal() { | ||
return { | ||
v: props.v, | ||
prev: prev | ||
}; | ||
}; | ||
hackGlobal = function hackGlobal() { | ||
return { | ||
v: props.v, | ||
prev: prev | ||
}; | ||
}; | ||
return null; | ||
}; | ||
return null; | ||
}; | ||
Comp = /*#__PURE__*/function (_Component) { | ||
(0, _inherits2["default"])(Comp, _Component); | ||
var Comp = /*#__PURE__*/function (_Component) { | ||
(0, _inherits2["default"])(Comp, _Component); | ||
var _super = (0, _createSuper2["default"])(Comp); | ||
var _super = (0, _createSuper2["default"])(Comp); | ||
function Comp(props) { | ||
var _this; | ||
function Comp() { | ||
var _this; | ||
(0, _classCallCheck2["default"])(this, Comp); | ||
_this = _super.call(this, props); | ||
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", { | ||
v: null | ||
}); | ||
(0, _classCallCheck2["default"])(this, Comp); | ||
ufakeSet = function ufakeSet(v) { | ||
_this.setState({ | ||
v: v | ||
}); | ||
}; | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return _this; | ||
} | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", { | ||
v: null | ||
}); | ||
return _this; | ||
} | ||
(0, _createClass2["default"])(Comp, [{ | ||
key: "render", | ||
value: function render() { | ||
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Foo, { | ||
v: this.state.v | ||
}); | ||
} | ||
}]); | ||
return Comp; | ||
}(_react.Component); | ||
(0, _createClass2["default"])(Comp, [{ | ||
key: "setV", | ||
value: function setV(v) { | ||
this.setState({ | ||
v: v | ||
}); | ||
(0, _reshowUnit.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Comp, {})); | ||
(0, _chai.expect)(hackGlobal()).to.deep.equal({ | ||
v: null, | ||
prev: undefined | ||
}); | ||
_context.next = 6; | ||
return (0, _reshowUnit.act)(function () { | ||
return ufakeSet("bar"); | ||
}); | ||
case 6: | ||
(0, _chai.expect)(hackGlobal()).to.deep.equal({ | ||
v: "bar", | ||
prev: null | ||
}); | ||
case 7: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, { | ||
key: "render", | ||
value: function render() { | ||
return /*#__PURE__*/_react["default"].createElement(Foo, { | ||
v: this.state.v | ||
}); | ||
} | ||
}]); | ||
return Comp; | ||
}(_react.Component); | ||
var wrap = (0, _reshowUnit.mount)( /*#__PURE__*/_react["default"].createElement(Comp, null)); | ||
(0, _chai.expect)(hackGlobal()).to.deep.equal({ | ||
v: null, | ||
prev: undefined | ||
}); | ||
wrap.instance().setV("bar"); | ||
(0, _chai.expect)(hackGlobal()).to.deep.equal({ | ||
v: "bar", | ||
prev: null | ||
}); | ||
}); | ||
} | ||
}, _callee); | ||
}))); | ||
}); |
@@ -1,5 +0,5 @@ | ||
import React from "react"; | ||
import { expect } from "chai"; | ||
import { mount, cleanIt } from "reshow-unit"; | ||
import { render, unmount, cleanIt } from "reshow-unit"; | ||
import useMounted from "../useMounted"; | ||
import { jsx as _jsx } from "react/jsx-runtime"; | ||
describe("test useMounted", function () { | ||
@@ -17,7 +17,7 @@ afterEach(function () { | ||
var wrap = mount( /*#__PURE__*/React.createElement(Foo, null)); | ||
render( /*#__PURE__*/_jsx(Foo, {})); | ||
expect(hackGlobal()).to.be["true"]; | ||
wrap.unmount(); | ||
unmount(); | ||
expect(hackGlobal()).to.be["false"]; | ||
}); | ||
}); |
@@ -0,1 +1,2 @@ | ||
import _regeneratorRuntime from "reshow-runtime/regenerator"; | ||
import _classCallCheck from "reshow-runtime/es/helpers/classCallCheck"; | ||
@@ -7,76 +8,88 @@ import _createClass from "reshow-runtime/es/helpers/createClass"; | ||
import _defineProperty from "reshow-runtime/es/helpers/defineProperty"; | ||
import React, { Component } from "react"; | ||
import _asyncToGenerator from "reshow-runtime/es/helpers/asyncToGenerator"; | ||
import { Component } from "react"; | ||
import { expect } from "chai"; | ||
import { mount } from "reshow-unit"; | ||
import { render, act } from "reshow-unit"; | ||
import usePrevious from "../usePrevious"; | ||
import { jsx as _jsx } from "react/jsx-runtime"; | ||
describe("test usePrevious", function () { | ||
it("basic test", function () { | ||
var hackGlobal; | ||
it("basic test", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { | ||
var hackGlobal, Foo, ufakeSet, Comp; | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
Foo = function Foo(props) { | ||
var prev = usePrevious(props.v); | ||
var Foo = function Foo(props) { | ||
var prev = usePrevious(props.v); | ||
hackGlobal = function hackGlobal() { | ||
return { | ||
v: props.v, | ||
prev: prev | ||
}; | ||
}; | ||
hackGlobal = function hackGlobal() { | ||
return { | ||
v: props.v, | ||
prev: prev | ||
}; | ||
}; | ||
return null; | ||
}; | ||
return null; | ||
}; | ||
Comp = /*#__PURE__*/function (_Component) { | ||
_inherits(Comp, _Component); | ||
var Comp = /*#__PURE__*/function (_Component) { | ||
_inherits(Comp, _Component); | ||
var _super = _createSuper(Comp); | ||
var _super = _createSuper(Comp); | ||
function Comp(props) { | ||
var _this; | ||
function Comp() { | ||
var _this; | ||
_classCallCheck(this, Comp); | ||
_classCallCheck(this, Comp); | ||
_this = _super.call(this, props); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_defineProperty(_assertThisInitialized(_this), "state", { | ||
v: null | ||
}); | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
ufakeSet = function ufakeSet(v) { | ||
_this.setState({ | ||
v: v | ||
}); | ||
}; | ||
_defineProperty(_assertThisInitialized(_this), "state", { | ||
v: null | ||
}); | ||
return _this; | ||
} | ||
return _this; | ||
} | ||
_createClass(Comp, [{ | ||
key: "render", | ||
value: function render() { | ||
return /*#__PURE__*/_jsx(Foo, { | ||
v: this.state.v | ||
}); | ||
} | ||
}]); | ||
_createClass(Comp, [{ | ||
key: "setV", | ||
value: function setV(v) { | ||
this.setState({ | ||
v: v | ||
}); | ||
} | ||
}, { | ||
key: "render", | ||
value: function render() { | ||
return /*#__PURE__*/React.createElement(Foo, { | ||
v: this.state.v | ||
}); | ||
} | ||
}]); | ||
return Comp; | ||
}(Component); | ||
return Comp; | ||
}(Component); | ||
render( /*#__PURE__*/_jsx(Comp, {})); | ||
expect(hackGlobal()).to.deep.equal({ | ||
v: null, | ||
prev: undefined | ||
}); | ||
_context.next = 6; | ||
return act(function () { | ||
return ufakeSet("bar"); | ||
}); | ||
var wrap = mount( /*#__PURE__*/React.createElement(Comp, null)); | ||
expect(hackGlobal()).to.deep.equal({ | ||
v: null, | ||
prev: undefined | ||
}); | ||
wrap.instance().setV("bar"); | ||
expect(hackGlobal()).to.deep.equal({ | ||
v: "bar", | ||
prev: null | ||
}); | ||
}); | ||
case 6: | ||
expect(hackGlobal()).to.deep.equal({ | ||
v: "bar", | ||
prev: null | ||
}); | ||
case 7: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
}))); | ||
}); |
{ | ||
"version": "0.17.0", | ||
"name": "reshow-hooks", | ||
"version": "0.16.0", | ||
"repository": "react-atomic/reshow", | ||
"homepage": "https://github.com/react-atomic/reshow/tree/main/packages/reshow-hooks", | ||
"description": "Utilities for hook", | ||
"main": "./build/cjs/src/index.js", | ||
"module": "./build/es/src/index.js", | ||
"repository": "react-atomic/reshow", | ||
"homepage": "https://github.com/react-atomic/reshow/tree/main/packages/reshow-hooks", | ||
"keywords": [ | ||
@@ -20,5 +20,5 @@ "react-hook", | ||
"@babel/cli": "^7.x", | ||
"react": "16.x", | ||
"react-dom": "16.x", | ||
"reshow-unit": "^0.16.0" | ||
"react": "18.x", | ||
"react-dom": "18.x", | ||
"reshow-unit": "^0.17.x" | ||
}, | ||
@@ -30,3 +30,3 @@ "scripts": { | ||
"build": "npm run clean && npm run build:cjs && npm run build:es", | ||
"mochaFor": "mocha -r jsdom-global/register", | ||
"mochaFor": "mocha -r global-jsdom/register", | ||
"mocha": "npm run mochaFor -- 'build/cjs/**/__tests__/*.js'", | ||
@@ -40,4 +40,3 @@ "test": "npm run build && npm run mocha", | ||
"README.md" | ||
], | ||
"gitHead": "be1806f6f2d188920e2c36ff2c150e584ef7d7fc" | ||
] | ||
} |
14815
398