vendredi 22 mars 2019

Spy a method that has been called when onPress on an Alert

I am trying to test a removeService method that gets called when onPress 'ing inside an Alert like this

Alert.alert(
      [...],
          onPress: () => removeService();
    );
  }

this is the test:

    const spyAlert = jest.spyOn(Alert, 
    "alert");
    const spyRemoveService = jest.fn();
    const wrapper = shallow(
      <AddServiceProgressScreen removeService={spyRemoveService} />
    );

    wrapper
      .find("RemoveServiceButton")
      .props()
      .handleRemoveService();

    // Click onPress
    spyAlert.mock.calls[0][2][1].onPress();

    expect(spyRemoveService).toHaveBeenCalledTimes(1);

However, when I run the test I get TypeError: removeService is not a function

why?

Aucun commentaire:

Enregistrer un commentaire