@enact/core
Version:
Enact is an open source JavaScript framework containing everything you need to create a fast, scalable mobile or web application.
46 lines (45 loc) • 2.47 kB
JavaScript
;
require("@testing-library/jest-dom");
var _react = require("@testing-library/react");
var _react2 = require("react");
var _useChainRefs = _interopRequireDefault(require("../useChainRefs"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
describe('useChainRefs', function () {
function Component(props) {
var ref = _useChainRefs["default"].apply(void 0, _toConsumableArray(props.refs));
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
ref: ref
});
}
test('should call a single functional ref', function () {
var ref = jest.fn();
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
refs: [ref]
}));
expect(ref).toHaveBeenCalledTimes(1);
});
test('should call a single object ref', function () {
var ref = /*#__PURE__*/(0, _react2.createRef)();
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
refs: [ref]
}));
var expected = 'DIV';
var actual = ref.current.nodeName;
expect(actual).toBe(expected);
});
test('should ignore invalid refs', function () {
var invalid = {};
var ref = jest.fn();
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
refs: [invalid, ref]
}));
expect(ref).toHaveBeenCalledTimes(1);
});
});