I'm new to testing and jest. I'm using it together with react testing library to test a react application.
Particularly, I'm trying to test a header button that is responsible for changing the language of the website. As I understand so far, it's better to test for the "results" of the action (the text in the desired language rendered on the screen) rather than for the "logic" (the state of the app changing), so that's what I'm trying to do.
The actual test is the following:
test('Changes language on click', () => {
render( <BrowserRouter> <Header /> </BrowserRouter> )
userEvent.click(screen.getByTestId('es-language-btn'))
expect(screen.getByTestId('about-desktop-btn')).toHaveTextContent('Sobre mi')
})
And the error I'm getting is this:
setEnglishLanguage function must be overridden
12 | setDarkModeOn: (): void => {throw new Error('setDarkModeOn function must be overridden')},
13 | englishLanguage: false,
> 14 | setEnglishLanguage: (): void => {throw new Error('setEnglishLanguage function must be overridden')}
| ^
15 | }
16 |
17 | const Context = createContext <ContextInterface>(defaultState)
setEnglishLanguage is the function responsible of the state change the button triggers, but I don't know what overriding it means or how should I do it.