Skip to content

Instantly share code, notes, and snippets.

@thomashagstrom
Last active January 15, 2019 15:56
Show Gist options
  • Save thomashagstrom/7faaf6390d3323d0213e48d22bee8187 to your computer and use it in GitHub Desktop.
Save thomashagstrom/7faaf6390d3323d0213e48d22bee8187 to your computer and use it in GitHub Desktop.
Callback on React child using Jest
import React from 'react';
import CrossButton from './CrossButton';
import TestRenderer from 'react-test-renderer';
describe('components', () => {
describe('<CrossButton />', () => {
it('<FontAwesome.Button /> onPress should be called', () => {
let called = false;
const onCalled = () => (called = !called);
const wrapper = TestRenderer.create(
<CrossButton
onPress={onCalled}
/>);
const child = wrapper.root.findByProps({ testID: 'FontAwesomeButton' });
child.props.onPress();
expect(called).toBeTruthy();
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment