Skip to content

Instantly share code, notes, and snippets.

@emilong
Created October 21, 2016 19:29
Show Gist options
  • Save emilong/85d378bda92eda6483ee535a9347569a to your computer and use it in GitHub Desktop.
Save emilong/85d378bda92eda6483ee535a9347569a to your computer and use it in GitHub Desktop.
// Link.react-test.js
import React from 'react';
import Link from '../Link.react';
import renderer from 'react-test-renderer';
test('Link changes the class when hovered', () => {
const component = renderer.create(
<Link page="http://www.facebook.com">Facebook</Link>
);
let tree = component.toJSON();
expect(tree).toMatchSnapshot();
// manually trigger the callback
tree.props.onMouseEnter();
// re-rendering
tree = component.toJSON();
expect(tree).toMatchSnapshot();
// manually trigger the callback
tree.props.onMouseLeave();
// re-rendering
tree = component.toJSON();
expect(tree).toMatchSnapshot();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment