Detox icon indicating copy to clipboard operation
Detox copied to clipboard

Interacting with Redux State in tests

Open micahdasMA opened this issue 1 year ago • 5 comments

Description

I am using Detox to test a react-native app I have. Part of the app flow involves logging in in order to access certain parts of the app. I would like to test specific aspects of the app past the login screen, but I don't want to have to login in each time that the test runs as that introduces additional complexity and is not actually the traditional user flow (users would typically stay logged in after they initially logged in to the app).

I am trying to find a way to set the redux state before launching the app, or some way to specifically mock the state of the app after opening it.

I looked through the docs on Mocking, but it did not seem like there was anything about directly interacting with redux

I tried launching the app as a new instance, then calling the redux store to set the state that a logged in user would have, and then reloading the app, but this did not result in the user logged in

Your environment

Detox version: 20.11.0 React Native version: 0.72.1 Node version: 16.2.0 Device model: iPhone 14 OS: iOS Test-runner (select one): jest / other

micahdasMA avatar Oct 04 '23 23:10 micahdasMA

@micahdasMA, if such an API existed, do you think you would have been able to resolve your problem?

image

noomorph avatar Oct 05 '23 10:10 noomorph

Speaking about officially available solutions, I'd advise going with static mock files (per the Mocking Guide) where you would register test-only app protocol handlers, and then you could have used the device.openURL(...) API with a URL like myapp://[email protected].

noomorph avatar Oct 05 '23 10:10 noomorph

@noomorph I think that would do exactly what I want! Thanks for sharing.

In the meantime, I will see what I can do with the app protocol handlers.

micahdasMA avatar Oct 05 '23 18:10 micahdasMA

Minor correction: device.launchApp({ url: '...' }), not device.openURL() - although the latter might work too as well, but I am not 100% sure.

noomorph avatar Oct 05 '23 18:10 noomorph

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest Detox and report back.

Thank you for your contributions!

For more information on bots in this repository, read this discussion.

stale[bot] avatar Dec 15 '23 04:12 stale[bot]