Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Latest commit

 

History

History
47 lines (33 loc) · 908 Bytes

simulate.md

File metadata and controls

47 lines (33 loc) · 908 Bytes

.simulate(event[, mock]) => Self

Simulate events

Arguments

  1. event (String): The event name to be simulated
  2. mock (Object [optional]): A mock event object that will be merged with the event object passed to the handlers.

Returns

ReactWrapper: Returns itself.

Example

class Foo extends React.Component {
  constructor(props) {
    super(props);
    this.state = { count: 0 };
  }
  render() {
    const { count } = this.state;
    return (
      <div>
        <div className={`clicks-${count}`}>
          {count} clicks
        </div>
        <a href="url" onClick={() => { this.setState({ count: count + 1 }); }}>
          Increment
        </a>
      </div>
    );
  }
}

const wrapper = mount(<Foo />);

expect(wrapper.find('.clicks-0').length).to.equal(1);
wrapper.find('a').simulate('click');
expect(wrapper.find('.clicks-1').length).to.equal(1);