Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added some new assertions on tests #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"jest": "^22.4.3",
"react-test-renderer": "^16.3.2",
"enzyme": "3.3.0",
"enzyme-adapter-react-16": "1.1.1"
"enzyme-adapter-react-16": "1.1.1",
"sinon": "4.5.0"
}
}
1 change: 1 addition & 0 deletions src/components/card/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const card = ({ icon, title, desc, onClick }) => {
className="card bg-white ba br4 b--black-20 pointer grow"
onClick={onClick}>


<hr className="ma0 ntPoint5 center w-30 ba b--black-20" />
<hr className="ma0 ntPoint5 center w-30 ba b--black-20" />
<div className="card-body content-center tc pa4 pb5">
Expand Down
2 changes: 1 addition & 1 deletion src/tests/__snapshots__/card.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ exports[`Matches 1`] = `
<h2
className="b f2 mb4"
>
This is not a card
This is a card
</h2>
<p
className="f4 lh-copy"
Expand Down
18 changes: 12 additions & 6 deletions src/tests/card.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import React from 'react';
import Card from "../components/card";
import renderer from "react-test-renderer";
import Adapter from 'enzyme-adapter-react-16';
import Enzyme,{ shallow } from 'enzyme';
import Enzyme,{ shallow, mount } from 'enzyme';
import sinon from "sinon";

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

test("Matches", () => {
const component = renderer.create(
<Card
icon="make-payment.png"
title="This is not a card"
title="This is a card"
desc="This is a card"
onClick={() => {}} />
);
Expand All @@ -20,14 +21,19 @@ test("Matches", () => {
})

test("Renders <HR /> & <div>", () => {
const wrapper = shallow(
const onButtonClick = sinon.spy();
const wrapper = mount(
<Card
icon="make-payment.png"
title="This is not a card"
desc="This is a card"
onClick={() => {}} />
onClick={onButtonClick} />
)

expect(wrapper.find("hr")).toHaveLength(2);
expect(wrapper.find("div")).toHaveLength(2);

wrapper.find(".card").simulate('click');
wrapper.find(".card").simulate('click');
expect(wrapper.props().desc).toBe("This is a card")
// console.log(onButtonClick);
expect(onButtonClick).toHaveProperty('callCount', 2);
})