Skip to content

Instantly share code, notes, and snippets.

@vvo

vvo/test.js

Created Oct 20, 2015
Embed
What would you like to do?
onClick test
import React from 'react';
import expect from 'expect';
import {createRenderer} from 'react-addons-test-utils';
import expectJSX from 'expect-jsx';
expect.extend(expectJSX);
import Button from './Button.js';
import Label from './Label.js';
describe('Button', () => {
it('works', () => {
let renderer = createRenderer();
renderer.render(<Button name="John" click={() => {}} />);
let actualElement = renderer.getRenderOutput();
let expectedElement = <div onClick={() => {}}><Label name="John" /></div>;
expect(actualElement).toEqualJSX(expectedElement);
});
it('clicks', () => {
let renderer = createRenderer();
let hasClicked = false;
let click = () => hasClicked = true;
renderer.render(<Button name="John" click={click} />);
renderer.getRenderOutput().props.onClick();
expect(hasClicked).toBe(true);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment