UNPKG

@gravity-ui/data-source

Version:
58 lines 2.28 kB
import _objectSpread from "@babel/runtime/helpers/objectSpread2"; import React from 'react'; import { render, screen } from '@testing-library/react'; import { useDataManager } from '../DataManagerContext'; import { withDataManager } from '../withDataManager'; import { jsx as _jsx } from "react/jsx-runtime"; jest.mock('../DataManagerContext', function () { var originalModule = jest.requireActual('../DataManagerContext'); return _objectSpread(_objectSpread({}, originalModule), {}, { useDataManager: jest.fn() }); }); describe('withDataManager', function () { var mockDataManager = { normalizer: undefined, optimisticUpdate: jest.fn(), invalidateData: jest.fn(), invalidateTag: jest.fn(), invalidateTags: jest.fn(), invalidateSource: jest.fn(), resetSource: jest.fn(), invalidateParams: jest.fn(), resetParams: jest.fn(), invalidateSourceTags: jest.fn() }; beforeEach(function () { jest.clearAllMocks(); useDataManager.mockReturnValue(mockDataManager); }); it('should pass dataManager to wrapped component', function () { var TestComponent = function TestComponent(_ref) { var dataManager = _ref.dataManager; return /*#__PURE__*/_jsx("div", { "data-testid": "test-component", children: dataManager ? 'DataManager provided' : 'No DataManager' }); }; var WrappedComponent = withDataManager(TestComponent); render(/*#__PURE__*/_jsx(WrappedComponent, {})); expect(screen.getByTestId('test-component')).toHaveTextContent('DataManager provided'); }); it('should pass through additional props', function () { var TestComponent = function TestComponent(_ref2) { var dataManager = _ref2.dataManager, testProp = _ref2.testProp; return /*#__PURE__*/_jsx("div", { "data-testid": "test-component", children: dataManager ? "DataManager provided, testProp: ".concat(testProp) : 'No DataManager' }); }; var WrappedComponent = withDataManager(TestComponent); render(/*#__PURE__*/_jsx(WrappedComponent, { testProp: "test value" })); expect(screen.getByTestId('test-component')).toHaveTextContent('DataManager provided, testProp: test value'); }); }); // #sourceMappingURL=withDataManager.test.js.map