Skip to content

React-testing-library 5.0.0: fireEvent 'change' is not triggered #162

Closed
@snaumov

Description

@snaumov
  • react-testing-library version:5.0.0
  • react version: 16.3.1, ^16.4.2
  • node version: 8.11.4
  • npm (or yarn) version: yarn 1.9.4

Relevant code or config:

// TEST
import { render, fireEvent } from 'react-testing-library';
import App from './App';

it('Testing library fireEvent fires event', () => {
  const handleChange = jest.fn();
  const {getByTestId} = render(<App handleChange={handleChange}/>);
  const input = getByTestId('test-input');
  input.value = 'TEST VALUE';
  fireEvent.change(input);
  expect(handleChange).toHaveBeenCalledTimes(1);
});

//COMPONENT

class App extends Component {

    constructor(props) {
        super(props);
        this.state = {
            value: ''
        };
        this.handleChange = this.handleChange.bind(this);
    }

    handleChange = (e) => {
        console.log('calling handle change');
        const { value } = e.target;
        this.setState({ value });
        this.props.handleChange(e);
    };

  render() {
    return (
      <div className="App">
        <input value={this.state.value} onChange={this.handleChange} data-testid="test-input" />
      </div>
    );
  }
}

export default App;

Reproduction:

https://github.com/snaumov/repro-for-kent

Problem description:

The above test fails on react-testing-library 5.0.0 (handleChange not fired), but works in 4.1.8.

Suggested solution:

Will keep looking into that, appreciate any direction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions