Skip to content

Commit

Permalink
Make tests better
Browse files Browse the repository at this point in the history
  • Loading branch information
belcherj committed Sep 23, 2019
1 parent 32e0b00 commit 40a4b8b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 32 deletions.
28 changes: 1 addition & 27 deletions lib/components/checkbox/__snapshots__/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 Checkbox correctly when checked 1`] = `
exports[`hasn't had its output unintentionally altered 1`] = `
<span
aria-checked={false}
className="checkbox"
Expand Down Expand Up @@ -29,29 +29,3 @@ exports[`renders Checkbox correctly when checked 1`] = `
</span>
</span>
`;

exports[`renders Checkbox correctly when not checked 1`] = `
<span
aria-checked={true}
className="checkbox"
role="checkbox"
tabIndex="0"
>
<span
aria-hidden="true"
className="checkbox__icon"
>
<svg
className="icon-checkmark"
height="24px"
viewBox="0 0 24 24"
width="24px"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M11,17.768l-4.884-4.884l1.768-1.768L11,14.232l8.658-8.658C17.823,3.391,15.075,2,12,2C6.477,2,2,6.477,2,12 s4.477,10,10,10s10-4.477,10-10c0-1.528-0.353-2.971-0.966-4.266L11,17.768z"
/>
</svg>
</span>
</span>
`;
20 changes: 15 additions & 5 deletions lib/components/checkbox/test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import React from 'react';
import Checkbox from './';
import CheckmarkIcon from '../../icons/checkmark';
import CircleIcon from '../../icons/circle';
import React from 'react';
import renderer from 'react-test-renderer';
import { shallow } from 'enzyme';

it('renders Checkbox correctly when checked', () => {
it("hasn't had its output unintentionally altered", () => {
const tree = renderer.create(<Checkbox checked={false}></Checkbox>).toJSON();
expect(tree).toMatchSnapshot();
});

it('renders Checkbox correctly when not checked', () => {
const tree = renderer.create(<Checkbox checked={true}></Checkbox>).toJSON();
expect(tree).toMatchSnapshot();
it('renders the circle icon when unchecked', () => {
const checkbox = shallow(<Checkbox checked={false}></Checkbox>);
expect(checkbox.find(CircleIcon)).toHaveLength(1);
expect(checkbox.find(CheckmarkIcon)).toHaveLength(0);
});

it('renders the checkmark icon when checked', () => {
const checkbox = shallow(<Checkbox checked={true}></Checkbox>);
expect(checkbox.find(CircleIcon)).toHaveLength(0);
expect(checkbox.find(CheckmarkIcon)).toHaveLength(1);
});

it('should call onChange prop when span is clicked', () => {
Expand Down

0 comments on commit 40a4b8b

Please sign in to comment.