Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.