Test run faster, then my function finish. React, Enzyme + Jest

Viewed 50

I try to test function, that after finish API request shall display displayModalSuccess.

someFunction = () => {
      displayModalLoading()
      Promise.all([execDelete(something here...)])
      .then(function(){
         displayModalSuccess()
        return({something...}.bind(this))

In my test I have tested if someFunction is called, and i want to find succes modal, but its not there yet.

 someFunction: jest.fn().mockImplementation(() => Promise.resolve({}))
    
     .....

     // (my part of test related to topic)
    
     expect(someFunction).toHaveBeenCalledTimes(1);
    
     expect(wrapper.find('.t-btn-modal-delete-success').length).toEqual(1);

     ....

I have also put console.log() into code, and into test. The test console.log(), runs first, so that means that succes modal is not there yet, when test runs?

How can I make this test succesfull, I guess I have to wait somehow on function to finish?

Im new in testing, happy for every answer.

0 Answers
Related