Created
October 16, 2017 04:36
-
-
Save burgwyn/619b1b9861dfe121c69a75f63c41cfdb to your computer and use it in GitHub Desktop.
Assertions using Jest, Enzyme, and Snapshots
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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