Simulating Events & Assertions
wrapper.simulate(event[, mock])
|
Simulates an event on the selected node(s).
wrapper.find('button').simulate('click');
wrapper.find('input').simulate('change', { target: { value: 'new value' } });
|
|
click , change , submit , keyDown , keyUp , mouseEnter , mouseLeave
|
|
Checks if elements matching the selector exist.
expect(wrapper.exists('button')).toBe(true);
|
|
Returns the text content of the node(s).
expect(wrapper.find('p').text()).toEqual('Hello World');
|
|
Returns the HTML content of the node(s).
expect(wrapper.find('div').html()).toEqual('<div class="my-class">...</div>');
|
|
Returns all props of the root node.
expect(wrapper.props().className).toEqual('my-class');
|
|
Returns a specific prop of the root node.
expect(wrapper.prop('id')).toEqual('uniqueId');
|
|
Gets the state of a stateful component. If key is provided, returns the value of that key. Otherwise, returns the entire state object. (Only for mount and shallow with stateful components)
wrapper.setState({ count: 1 });
expect(wrapper.state('count')).toEqual(1);
|
|
Sets the props of the component. Triggers a re-render. (Only for mount and shallow )
wrapper.setProps({ name: 'New Name' });
expect(wrapper.prop('name')).toEqual('New Name');
|
|
Forces a re-render of the component. Useful when props or state have been updated indirectly.
wrapper.update();
|