forked from zoltantothcom/Design-Patterns-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResult.test.js
More file actions
53 lines (46 loc) · 1.38 KB
/
Result.test.js
File metadata and controls
53 lines (46 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import React from 'react';
import renderer from 'react-test-renderer';
import { shallow } from 'enzyme';
import { Provider } from 'react-redux';
import configureMockStore from 'redux-mock-store';
import 'jest-styled-components';
import Result from '../../src/components/Result';
const mockStore = configureMockStore();
const store = mockStore({
progress: {
answers: [
{ id: 1, correct: true },
{ id: 2, correct: true },
{ id: 3, correct: true },
{ id: 4, correct: false }
]
}
});
describe('<Result /> component', () => {
let result;
beforeEach(() => {
// the wrapper DIV added to get rid of iterator key warning
result = shallow(
<div key="key">
<Provider store={store} key="unique">
<Result key="result" />
</Provider>
</div>
);
});
it('renders without crashing', () => {
expect(result).toBeTruthy();
});
it('shows the number of correct answers', () => {
const expected = '<strong>3</strong> patterns right out of 4.';
expect(result.html()).toEqual(expect.stringContaining(expected));
});
it('has styled-component rendered classes', () => {
const tree = renderer.create(result).toJSON();
expect(tree.children[0].props.className).toBeDefined();
});
it('matches the snapshot', () => {
const tree = renderer.create(result).toJSON();
expect(tree).toMatchSnapshot();
});
});