Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.