Skip to content

Commit 130ffd0

Browse files
author
yocosaka
committed
Add tests for Home, ListFilters, and MoviesList
1 parent 398a1e7 commit 130ffd0

File tree

6 files changed

+85
-22
lines changed

6 files changed

+85
-22
lines changed

src/tests/components/Home.test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React from 'react';
2+
import { Provider } from 'react-redux';
3+
import { BrowserRouter } from 'react-router-dom';
4+
import { render } from '@testing-library/react';
5+
import renderer from 'react-test-renderer';
6+
import Home from '../../components/Home';
7+
import createTestStore from '../fixtures/createTestStore';
8+
9+
describe('Home', () => {
10+
let store;
11+
beforeEach(() => {
12+
store = createTestStore();
13+
});
14+
15+
test('should render the initial message before users search a movie', async () => {
16+
const { findByText } = render(
17+
<Provider store={store}>
18+
<Home />
19+
</Provider>,
20+
);
21+
await findByText('Sorry, any movies have not been found. Try to search again!');
22+
});
23+
24+
test('should match with snapshot', () => {
25+
const jsx = (
26+
<Provider store={store}>
27+
<BrowserRouter>
28+
<Home />
29+
</BrowserRouter>
30+
</Provider>
31+
);
32+
const tree = (() => renderer.create(jsx).toJSON());
33+
expect(tree).toMatchSnapshot();
34+
});
35+
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React from 'react';
2+
import { Provider } from 'react-redux';
3+
import { BrowserRouter } from 'react-router-dom';
4+
import { render } from '@testing-library/react';
5+
import renderer from 'react-test-renderer';
6+
import ListFilters from '../../components/ListFilters';
7+
import createTestStore from '../fixtures/createTestStore';
8+
9+
describe('ListFilters', () => {
10+
let store;
11+
beforeEach(() => {
12+
store = createTestStore();
13+
});
14+
15+
test('should render the initial message before users search a movie', async () => {
16+
const { findByText } = render(
17+
<Provider store={store}>
18+
<ListFilters />
19+
</Provider>,
20+
);
21+
await findByText('2020-2021');
22+
});
23+
24+
test('should match with snapshot', () => {
25+
const jsx = (
26+
<Provider store={store}>
27+
<BrowserRouter>
28+
<ListFilters />
29+
</BrowserRouter>
30+
</Provider>
31+
);
32+
const tree = (() => renderer.create(jsx).toJSON());
33+
expect(tree).toMatchSnapshot();
34+
});
35+
});

src/tests/components/MoviesList.test.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { render } from '@testing-library/react';
55
import renderer from 'react-test-renderer';
66
import MoviesList from '../../components/MoviesList';
77
import createTestStore from '../fixtures/createTestStore';
8-
// import movieData from '../fixtures/movieData';
98

109
describe('MoviesList', () => {
1110
let store;
@@ -23,15 +22,14 @@ describe('MoviesList', () => {
2322
});
2423

2524
test('should match with snapshot', () => {
26-
const tree = renderer
27-
.create(
28-
<Provider store={store}>
29-
<BrowserRouter>
30-
<MoviesList />
31-
</BrowserRouter>
32-
</Provider>,
33-
)
34-
.toJSON();
25+
const jsx = (
26+
<Provider store={store}>
27+
<BrowserRouter>
28+
<MoviesList />
29+
</BrowserRouter>
30+
</Provider>
31+
);
32+
const tree = (() => renderer.create(jsx).toJSON());
3533
expect(tree).toMatchSnapshot();
3634
});
3735
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Home should match with snapshot 1`] = `[Function]`;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`ListFilters should match with snapshot 1`] = `[Function]`;
Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`MoviesList should match with snapshot 1`] = `
4-
<div>
5-
<p
6-
className="error-msg"
7-
>
8-
Sorry, any movies have not been found. Try to search again!
9-
</p>
10-
<div
11-
className="movies"
12-
/>
13-
</div>
14-
`;
3+
exports[`MoviesList should match with snapshot 1`] = `[Function]`;

0 commit comments

Comments
 (0)