mercredi 13 mars 2019

0 node found instead - OnClick

Not really sure why is not being able to find the element and get Onclick event to pass. Using Jest and Enzyme for React JS

Here is what I have done so far

beforeEach(() => wrapper = shallow(<Component  {...baseProps} />));

it("should call button click event on FINISH", () => {
 baseProps.onClick.mockClear(); 
 baseProps.closeModal.mockClear();
  wrapper.setState({
    INITIAL_STATE:{}
    }); 
    wrapper.update();
wrapper.find('#Finish-testclick').prop('onClick');
expect(baseProps.closeModal).toHaveBeenCalled();
});

Also tried the following

wrapper.find('#Finish-testclick').simulate('click');

here is the code:

<Modal>
  <button className={'tran-button export-selected'} id='Finish-testclick' onClick={() => {this.closeModal()}}>
   Finish
  </button>
    </div>
    }        
    </div>
  </Modal>

Close Modal method

closeModal = () => {
this.props.closeModal();
this.setState(INITIAL_STATE);
}

Aucun commentaire:

Enregistrer un commentaire