import React from 'react'; import { render } from '@testing-library/react'; import { useResourceDefinitions } from './useResourceDefinitions'; import { ResourceDefinitionContextProvider } from './ResourceDefinitionContext'; describe('useResourceDefinitions', () => { const UseResourceDefinitions = ({ callback, }: { resource?: string; callback: (params: any) => void; }) => { const resourceDefinition = useResourceDefinitions(); callback(resourceDefinition); return ; }; it('should not fail when used outside of a ResourceDefinitionContext', () => { const callback = jest.fn(); render(); expect(callback).toHaveBeenCalledWith({}); }); it('should use the definition from ResourceDefinitionContext', () => { const callback = jest.fn(); render( ); expect(callback).toHaveBeenCalledWith({ posts: { options: { label: 'Posts' }, }, comments: { options: { label: 'Comments' }, }, }); }); });