Hello Friends 👋,

Welcome To Infinitbility! ❤️

React Native detox tutorial

1. React native detox example

2. React native detox multiple typeText crash issues

3. React native detox with react navigation example

4. react-native-date-picker detox example

5. react-native-otp-input detox example

Github source repo

When react-native navigate to another screen detox all test cases failed and now we start thinking about how to stop detox test cases execution when react-native navigate to another screen.

Today, we will see how we can stop execution for a set of times.

React navigation takes a max of 2 seconds to navigate to another screen then we will stop execution for 2 seconds when the screen is navigating.

Let start code.

following code, I have added a function waitToNavigate() and we will call when the screen is navigating.

const waitToNavigate = duration => new Promise(resolve => setTimeout(() => resolve(), duration));

describe('Example', () => {
  beforeAll(async () => {
    await device.launchApp();
  });
  it('should have login screen', async () => {
    await expect(element(by.id('loginView'))).toBeVisible();
  });
  it('should fill login form', async () => {
    await element(by.id('emailInput')).replaceText('[email protected]');
    await element(by.id('passwordInput')).replaceText('1234');
    await element(by.id('loginButton')).tap();
    await expect(element(by.text('[email protected]'))).toBeVisible();

    // close alert
    await element(by.text('OK')).tap();

    // navigate to register screen
    await element(by.id('navigateRegister')).tap();
    await waitToNavigate(2000);
  });
  it('should have register screen', async () => {
    await expect(element(by.id('registerView'))).toBeVisible();
  });
  it('should fill login form', async () => {
    await element(by.id('emailInput')).replaceText('[email protected]');
    await element(by.id('passwordInput')).replaceText('1234');
    await element(by.id('registerButton')).tap();
  });
});

Thanks for reading…