Skip to content

Instantly share code, notes, and snippets.

@ricca509
Created February 20, 2017 22:56
Show Gist options
  • Save ricca509/36b08b42410f1ed68e8e107aa25dd8a1 to your computer and use it in GitHub Desktop.
Save ricca509/36b08b42410f1ed68e8e107aa25dd8a1 to your computer and use it in GitHub Desktop.
snapshot-component-test-1
// BuyNow.jsx
const BuyNow = ({ price, text }) => (<div>
<span className="price">£{price}</span>
<button className="btn-primary">{text}</button>
</div>);
// BuyNow.test.jsx
import { shallow } from 'enzyme';
import BuyNow from '../BuyNow';
describe('The BuyNow component', () => {
it('renders with the right price', () => {
const props = { price: 25 };
const tree = shallow(<BuyNow {...props} />);
expect(tree.find('span').length()).toEqual(1);
expect(tree.find('span').text()).toEqual('£25');
expect(tree.find('span').hasClass('price')).toBe(true);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment