cerebral / overmind

Overmind - Frictionless state management
https://overmindjs.org
MIT License
1.58k stars 95 forks source link

[BUG] Can't mock overmind for jest snapshots #594

Open crimson-med opened 11 months ago

crimson-med commented 11 months ago

We are currently using overmind on a project and have added Jest snapshots for testing the coverage and the components.

import { render } from '@testing-library/react'
import Home from './page'

it(`renders correctly`, () => {
  const { container } = render(<Home />)
  expect(container).toMatchSnapshot()
})

Withing the home page a few sub components are rendered which use the useAppState function and this creates some issues within the test:

The Overmind hook could not find an Overmind instance on the context of React. Please make sure you use the Provider component at the top of your application and expose the Overmind instance there. Please read more in the React guide on the website

const { myState } = useAppState().api

How to make overmind compatible with the following types of tests.

dpraimeyuu commented 3 months ago

@crimson-med did you wrap your container in Overmind provider?