Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add support for conditional logic around elements #672

Closed
etaiklein opened this issue Apr 13, 2018 · 3 comments
Closed

Add support for conditional logic around elements #672

etaiklein opened this issue Apr 13, 2018 · 3 comments

Comments

@etaiklein
Copy link

This is a request to expose the ability to run code conditionally in detox tests based on the existence of elements.

For example:

const mainScreen = element(by.id('mainScreen'));
if (!mainScreen) {
  await doOnboarding();
}
await expect(mainScreen).toBeVisible();
@etaiklein etaiklein changed the title Add conditional logic around elements Add support for conditional logic around elements Apr 13, 2018
@LeoNatan
Copy link
Contributor

LeoNatan commented Apr 16, 2018

You can try/catch expectations and branch from that to the rest of your logic.

So:

try {
  expect(mainScreen).toBeVisible();
}
catch {
  await doOnboarding();
}

@rotemmiz
Copy link
Member

Tests with branches are bad tests in my opinion.
A test should have a predictable input, and a predictable output.
If it branches it's not one test, but two.

Try making your input predictable by mocking what needs to be mocked.

@etaiklein
Copy link
Author

Try/catch will work thanks!

We need the branching logic to setup the tests the same on different logged in accounts- the tests themselves definitely shouldn’t branch.

Using mocked data doesn’t work for our use case since we want to test dependent services as well.

@wix wix locked and limited conversation to collaborators Jul 23, 2018
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants