Testing React components with Jest I got an error: "Warning: Failed context type: The context `router` is marked as required in `Link`, but its value is `undefined`.". I am using Link from react-router-dom in snapshot rendering with enzyme mount. The solution was to wrap my component with "BrowserRouter" in my test.
Source code viewer
import { BrowserRouter } from 'react-router-dom' describe('<MyComponent />', () => { it('Snapshot render', () => { const wrapper = mount( <BrowserRouter> <MyCompontent t={jest.fn()} /> </BrowserRouter>, ); expect(toJson(wrapper.render())).toMatchSnapshot(); }); });Programming Language: ECMAScript