hotfix: sample component test to work with react-testing-library

This commit is contained in:
George Lima 2018-11-28 17:03:31 -03:00
parent 4cdc1a94af
commit ae6e44f613
3 changed files with 36 additions and 75 deletions

View File

@ -1,16 +1,20 @@
import React from 'react'; import React from 'react';
import { shallow } from 'enzyme'; import { render } from 'react-testing-library';
import toJson from 'enzyme-to-json'; import { MemoryRouter } from 'react-router-dom';
import 'jest-dom/extend-expect';
import { SidebarComponent } from '../../app/components/sidebar/index'; import { SidebarComponent } from '../../app/components/sidebar/index';
describe('<Sidebar />', () => { describe('<Sidebar />', () => {
describe('render()', () => { describe('render()', () => {
test('should render correctly', () => { test('should render correctly', () => {
const wrapper = shallow(<SidebarComponent />); const { asFragment } = render(
const component = wrapper.dive(); <MemoryRouter>
<SidebarComponent />
</MemoryRouter>,
);
expect(toJson(component)).toMatchSnapshot(); expect(asFragment()).toMatchSnapshot();
}); });
}); });
}); });

View File

@ -1,69 +1,30 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Sidebar /> render() should render correctly 1`] = ` exports[`<Sidebar /> render() should render correctly 1`] = `
<StyledComponent <DocumentFragment>
forwardedClass={ <div
Object { class="sc-bdVaJa fnXMXv"
"$$typeof": Symbol(react.forward_ref),
"attrs": Array [],
"componentStyle": ComponentStyle {
"componentId": "sc-bdVaJa",
"isStatic": true,
"rules": Array [
"
",
"
display: flex;
flex-direction: column;
width: 200px;
position: absolute;
left: 0;
top: 0;
height: 100vh;
background: #ccc;
",
"
",
],
},
"displayName": "styled.div",
"render": [Function],
"styledComponentId": "sc-bdVaJa",
"target": "div",
"toString": [Function],
"warnTooManyClasses": [Function],
"withComponent": [Function],
}
}
forwardedRef={null}
>
<Link
key="/"
replace={false}
to="/"
> >
Dashboard <a
</Link> href="/"
<Link >
key="/send" Dashboard
replace={false} </a>
to="/send" <a
> href="/send"
Send >
</Link> Send
<Link </a>
key="/receive" <a
replace={false} href="/receive"
to="/receive" >
> Receive
Receive </a>
</Link> <a
<Link href="/settings"
key="/settings" >
replace={false} Settings
to="/settings" </a>
> </div>
Settings </DocumentFragment>
</Link>
</StyledComponent>
`; `;

View File

@ -1,6 +1,2 @@
import Enzyme from 'enzyme'; jest.DEFAULT_TIMEOUT_INTERVAL = 20000;
import Adapter from 'enzyme-adapter-react-16'; jest.setTimeout(20000);
jest.DEFAULT_TIMEOUT_INTERVAL = 10000;
Enzyme.configure({ adapter: new Adapter() });