render-with-context.tsx 587 B

1234567891011121314151617181920
  1. import React from 'react'
  2. import { render, type RenderOptions } from '@testing-library/react'
  3. import { EditorProviders, type EditorProvidersProps } from './editor-providers'
  4. export function renderWithEditorContext(
  5. component: React.ReactElement,
  6. contextProps: EditorProvidersProps = {},
  7. renderOptions: RenderOptions = {}
  8. ) {
  9. const EditorProvidersWrapper = ({
  10. children,
  11. }: {
  12. children: React.ReactNode
  13. }) => <EditorProviders {...contextProps}>{children}</EditorProviders>
  14. return render(component, {
  15. wrapper: EditorProvidersWrapper,
  16. ...renderOptions,
  17. })
  18. }