UNPKG

@ozen-ui/kit

Version:

React component library

54 lines (53 loc) 2.1 kB
import { __assign, __awaiter, __generator, __read, __spreadArray } from "tslib"; import React, { useContext, useEffect } from 'react'; import { render as renderTest, act, } from '@testing-library/react'; import { OzenProvider, themeOzenDefault } from '../components/OzenProvider'; var WithProviders = function (_a) { var children = _a.children; return (React.createElement(OzenProvider, { ssr: { isEnabled: false }, theme: themeOzenDefault }, children)); }; export var render = function (component, options) { return renderTest(component, __assign({ wrapper: WithProviders }, options)); }; export var renderInAct = function (ui, options) { return __awaiter(void 0, void 0, void 0, function () { var component; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { component = render(ui, options); return [2 /*return*/]; }); }); })]; case 1: _a.sent(); return [2 /*return*/, component]; } }); }); }; export var TestConsumer = function (_a) { var context = _a.context, onValue = _a.onValue; var contextValue = useContext(context); useEffect(function () { onValue(contextValue); }, [contextValue]); return null; }; export var createTestConsumer = function (context) { var Component = function (_a) { var onValue = _a.onValue; return React.createElement(TestConsumer, { context: context, onValue: onValue }); }; return Component; }; var matches = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var container = render.apply(void 0, __spreadArray([], __read(args), false)).container; return container.children.length > 1 ? container.children : container.firstChild; }; export default matches;