Skip to content

How to simulate change events with react-numeric-input #6

@ksrawat

Description

@ksrawat

Hey @vlad-ignatov using react-numeric-input control has helped me a lot and serving my purpose. Now its time for some unit testing react-numeric-input with my project..

Some how the test cases you provided taking them as reference i can't simulate key-up/down/change events. Is their any best way to do it or am i making wrong direction. Following is the code.

`it('calls onChange when user press up arrow key', () => {
let onChangeCalls = 0
function onChange(x){
console.log('change function fired');
onChangeCalls += 1;
}

   var widget = TestUtils.renderIntoDocument(<MyNumericInput
                onChange={ onChange }
   />             
   )

   TestUtils.Simulate.keyDown(widget.refs.numericbox, {
        keyCode: KEYCODE_UP,
        ctrlKey: true
    })
   console.log(onChangeCalls); 
   expect(onChangeCalls).to.equal(1);
});`

Whereas MyNumericInput is my component wrapping react-numeric-input control inside it.

Let me know if you need more information on this..

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions