Skip to content

Commit b594c9e

Browse files
committed
fix requestAnimationFrame error, also added Gift component test
1 parent a74a789 commit b594c9e

File tree

7 files changed

+46
-24
lines changed

7 files changed

+46
-24
lines changed

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"enzyme": "^3.0.0",
1919
"enzyme-adapter-react-16": "^1.0.0",
2020
"jest-cli": "^20.0.4",
21+
"raf": "^3.3.2",
2122
"react-test-renderer": "^16.0.0-beta.5"
2223
}
2324
}

Diff for: src/components/App.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class App extends Component {
2424
<h2>Gift Giver</h2>
2525
<div className="gift-list">
2626
{
27-
this.state.gifts.map( (gift, index) => {
28-
return (<div key={index}></div>);
27+
this.state.gifts.map( gift => {
28+
return (<div key={gift.id}></div>);
2929
})
3030
}
3131
</div>

Diff for: src/components/App.test.js

+28-21
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,32 @@ import Adapter from 'enzyme-adapter-react-16';
55

66
configure({ adapter: new Adapter() });
77

8-
const app = shallow(<App />);
9-
10-
it('renders correctly', () => {
11-
expect(app).toMatchSnapshot();
12-
});
13-
14-
it('initializes the `state` with an empty list of gifts', () => {
15-
expect(app.state().gifts).toEqual([]);
16-
});
17-
18-
it('adds a new gift to `state` when clicking the `add gift` button', () => {
19-
app.find('.btn-add').simulate('click');
20-
21-
expect(app.state().gifts).toEqual([{ id: 1 }]);
22-
});
23-
24-
it('adds a new gift to the rendered list when clicking the `add gift` button', () => {
25-
app.find('.btn-add').simulate('click');
26-
27-
const listLength = app.find('.gift-list').children().length;
28-
expect(listLength).toEqual(2);
8+
describe('App', () => {
9+
const app = shallow(<App />);
10+
11+
it('renders correctly', () => {
12+
expect(app).toMatchSnapshot();
13+
});
14+
15+
it('initializes the `state` with an empty list of gifts', () => {
16+
expect(app.state().gifts).toEqual([]);
17+
});
18+
19+
describe('when clicking the `add gift` button', () => {
20+
beforeEach(() => {
21+
app.find('.btn-add').simulate('click');
22+
});
23+
afterEach(() => {
24+
app.setState({ gifts: [] });
25+
});
26+
27+
it('adds a new gift to `state`', () => {
28+
expect(app.state().gifts).toEqual([{ id: 1 }]);
29+
});
30+
31+
it('adds a new gift to the rendered list', () => {
32+
const listLength = app.find('.gift-list').children().length;
33+
expect(listLength).toEqual(1);
34+
});
35+
});
2936
});

Diff for: src/components/Gift.js

Whitespace-only changes.

Diff for: src/components/Gift.test.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from "react";
2+
import { shallow } from "enzyme";
3+
import Gift from "./components.Gift";
4+
5+
describe('Gift', () => {
6+
const gift = shallow(<Gift />);
7+
8+
it('should render', () => {
9+
expect(gift).toMatchSnapshot();
10+
})
11+
});

Diff for: src/components/__snapshots__/App.test.js.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`renders correctly 1`] = `
3+
exports[`App renders correctly 1`] = `
44
ShallowWrapper {
55
"length": 1,
66
Symbol(enzyme.__root__): [Circular],

Diff for: src/shim.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
global.requestAnimationFrame = callback => {
2+
setTimeout(callback, 0);
3+
};

0 commit comments

Comments
 (0)