Skip to content

How can we test API call with RNTL? #1337

@Saad-Bashar

Description

@Saad-Bashar

Ask your Question

Hi, sorry for the noob question here. I am new to testing. I wanted to know how can we cover the API test with RNTL? For example, I want to test the following.

const res = await sendFeedback(feedbackObj);
  if (res.data) {
    showMessage({
      message: 'Thanks for your feedback!',
      type: 'success',
      icon: 'success',
    });
    setIsSubmitting(false);
    Keyboard.dismiss();
    navigation.goBack();
  } else {
    showMessage({
      message: 'Something went wrong. Please try again later.',
      type: 'danger',
      icon: 'danger',
    });
    setIsSubmitting(false);
  }

Here I want to put a test condition for the success branch. Is this a right thing to do with RNTL or I should think in a different way? Thanks a lot!

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions