UNPKG

@gravity-ui/data-source

Version:
44 lines 1.54 kB
import React from 'react'; import { renderHook } from '@testing-library/react'; import { DataManagerContext, useDataManager } from '../DataManagerContext'; import { jsx as _jsx } from "react/jsx-runtime"; describe('useDataManager', function () { it('should return dataManager from context', 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() }; var wrapper = function wrapper(_ref) { var children = _ref.children; return /*#__PURE__*/_jsx(DataManagerContext.Provider, { value: mockDataManager, children: children }); }; var _renderHook = renderHook(function () { return useDataManager(); }, { wrapper: wrapper }), result = _renderHook.result; expect(result.current).toBe(mockDataManager); }); it('should throw an error when dataManager is not provided', function () { var consoleSpy = jest.spyOn(console, 'error').mockImplementation(); expect(function () { renderHook(function () { return useDataManager(); }); }).toThrow('DataManager is not provided by context. Use DataManagerContext.Provider to do it'); consoleSpy.mockRestore(); }); }); // #sourceMappingURL=DataManagerContext.test.js.map