- App-spec.js tests App.jsx that has a context provider context.js around Toolbar.jsx
We can also create children elements with mock context around them right from the test file. See Mock-context-spec.js file.
import { mount } from 'cypress-react-unit-test'
import { ThemeContext } from './context'
import { Toolbar } from './Toolbar.jsx'
it('passes given value', () => {
mount(
<ThemeContext.Provider value="mocked">
<Toolbar />
</ThemeContext.Provider>,
)
// confirm "mocked" value is passed to the Toolbar
})
For more complex context mock example, see bahmutov/sudoku repository.