Skip to content

Instantly share code, notes, and snippets.

@burgwyn
Created October 16, 2017 04:36
Show Gist options
  • Save burgwyn/619b1b9861dfe121c69a75f63c41cfdb to your computer and use it in GitHub Desktop.
Save burgwyn/619b1b9861dfe121c69a75f63c41cfdb to your computer and use it in GitHub Desktop.
Assertions using Jest, Enzyme, and Snapshots
import React from 'react';
import { shallow } from 'enzyme';
import toJSON from 'enzyme-to-json';
import StarRating from '../components/StarRating';
describe('StarRating sharedComponent', () => {
it('should match a snapshot', () => {
const wrapper = shallow(<StarRating />);
expect(toJSON(wrapper)).toMatchSnapshot();
});
it('should have a single review', () => {
const wrapper = shallow(<StarRating rating={1} voteCount={1} />);
expect(wrapper.find('.vote-count').text()).toBe('1 Review');
});
it('should handle half stars', () => {
const wrapper = shallow(<StarRating rating={3.5} voteCount={5} />);
expect(wrapper.find('.stars-container IconStarHalf')).toBeDefined();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment