Skip to content

Latest commit

 

History

History
24 lines (18 loc) · 829 Bytes

File metadata and controls

24 lines (18 loc) · 829 Bytes

Mocking context around the component

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
})

Mocked context screenshot

For more complex context mock example, see bahmutov/sudoku repository.