Skip to content

Commit

Permalink
test(header): fix error Invariant Violation: You should not use <Head…
Browse files Browse the repository at this point in the history
…er /> outside of <Router />

To test a component (with Jest) that contains <Route />'s stuff you need to import Router in you
test
  • Loading branch information
aneurysmjs committed Aug 11, 2019
1 parent b256492 commit e649c53
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/app/components/core/Header/Header.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
// @flow strict
import React from 'react';
import { act } from 'react-dom/test-utils';
import { BrowserRouter as Router } from 'react-router-dom';
// $FlowFixMe
import { render } from '@testing-library/react';

import Header from './Header';

describe('Header', () => {
it('tests something', () => {
const { container } = render(<Header />);
it('tests header\'s basics', async () => {
let testRenderer = {};

await act(async () => {
testRenderer = render(
<Router>
<Header />
</Router>,
);
});
const { container } = testRenderer;
const header = container.firstChild;
expect(header.className).toEqual('header');
});
Expand Down

0 comments on commit e649c53

Please sign in to comment.