0

I just tried Detox for e2e testing UI Automation. This library is really good. I just want to ask if there is any way for me to clear redux state after finishing a test suite. In my case, I want to clear my shopping cart

Here's my code:

import CartActions, {reducer, INITIAL_STATE} from '../../App/Redux/CartRedux'

describe('Add menu from home screen and do checkout', () => {
  it ('should navigate to meal detail screen after tapping first meal', async () => {
    await waitFor(element(by.id('MealListSlider'))).toBeVisible().withTimeout(7500)
    await element(by.id('homeMenu_0')).tap()
    await expect(element(by.id('MealDetailScreen'))).toBeVisible()
  })

  it ('should show shopping cart button after add item to cart', async () => {
    await element(by.id('addToCart_')).tap()
    await expect(element(by.id('shoppingCartButtonOnMealDetail'))).toBeVisible()
  })

  it ('should navigate to checkout screen', async () => {
    await element(by.id('shoppingCartButtonOnMealDetail')).tap()
    await expect(element(by.id('SingleOrderCheckoutScreen'))).toBeVisible()
  })

  afterAll(() => {
    reducer(INITIAL_STATE, CartActions.userEmptyingCart())
  })
})

I'm using Jest as my test runner. Please help me if I'm doing wrong. Thanks

Detox: 8.0.0 React Native: 0.47.2 Device: iOS Xcode: 9 macOS: High Sierra

Kevin Dave
  • 387
  • 2
  • 5
  • 19

1 Answers1

1

Probably you got confused regarding in which context Detox is running. The code of your Detox tests is running in the context of your computer and OS (like any Node.js app you run), but your application code is running on device/emulator/simulator.

The bottom line is that you cannot simply access your application code from the detox.

Normally, you would use device API methods like launchApp or reloadReactNative.

P. S. Random suggestion. If you indeed want to mess with Redux reducers from Detox, consider shipping a sort of "developer mode screen" with the development build of your app, access it from Detox and tap on a button you create for a specific use case. Turn on your imagination and creativity - maybe a specific keyboard listener will suffice (instead of an extra screen). But anyway, maybe stick to reloadReactNative - usually, it is enough.

noomorph
  • 837
  • 1
  • 6
  • 14