Skip to content

Commit

Permalink
fix requestAnimationFrame error, also added Gift component test
Browse files Browse the repository at this point in the history
  • Loading branch information
rogueITman committed Sep 28, 2017
1 parent a74a789 commit b594c9e
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 24 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"enzyme": "^3.0.0",
"enzyme-adapter-react-16": "^1.0.0",
"jest-cli": "^20.0.4",
"raf": "^3.3.2",
"react-test-renderer": "^16.0.0-beta.5"
}
}
4 changes: 2 additions & 2 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class App extends Component {
<h2>Gift Giver</h2>
<div className="gift-list">
{
this.state.gifts.map( (gift, index) => {
return (<div key={index}></div>);
this.state.gifts.map( gift => {
return (<div key={gift.id}></div>);
})
}
</div>
Expand Down
49 changes: 28 additions & 21 deletions src/components/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,32 @@ import Adapter from 'enzyme-adapter-react-16';

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

const app = shallow(<App />);

it('renders correctly', () => {
expect(app).toMatchSnapshot();
});

it('initializes the `state` with an empty list of gifts', () => {
expect(app.state().gifts).toEqual([]);
});

it('adds a new gift to `state` when clicking the `add gift` button', () => {
app.find('.btn-add').simulate('click');

expect(app.state().gifts).toEqual([{ id: 1 }]);
});

it('adds a new gift to the rendered list when clicking the `add gift` button', () => {
app.find('.btn-add').simulate('click');

const listLength = app.find('.gift-list').children().length;
expect(listLength).toEqual(2);
describe('App', () => {
const app = shallow(<App />);

it('renders correctly', () => {
expect(app).toMatchSnapshot();
});

it('initializes the `state` with an empty list of gifts', () => {
expect(app.state().gifts).toEqual([]);
});

describe('when clicking the `add gift` button', () => {
beforeEach(() => {
app.find('.btn-add').simulate('click');
});
afterEach(() => {
app.setState({ gifts: [] });
});

it('adds a new gift to `state`', () => {
expect(app.state().gifts).toEqual([{ id: 1 }]);
});

it('adds a new gift to the rendered list', () => {
const listLength = app.find('.gift-list').children().length;
expect(listLength).toEqual(1);
});
});
});
Empty file added src/components/Gift.js
Empty file.
11 changes: 11 additions & 0 deletions src/components/Gift.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react";
import { shallow } from "enzyme";
import Gift from "./components.Gift";

describe('Gift', () => {
const gift = shallow(<Gift />);

it('should render', () => {
expect(gift).toMatchSnapshot();
})
});
2 changes: 1 addition & 1 deletion src/components/__snapshots__/App.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renders correctly 1`] = `
exports[`App renders correctly 1`] = `
ShallowWrapper {
"length": 1,
Symbol(enzyme.__root__): [Circular],
Expand Down
3 changes: 3 additions & 0 deletions src/shim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
global.requestAnimationFrame = callback => {
setTimeout(callback, 0);
};

1 comment on commit b594c9e

@rogueITman
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.