Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

problems when using "waitFor" #138

Closed
irrigator opened this issue May 23, 2017 · 10 comments
Closed

problems when using "waitFor" #138

irrigator opened this issue May 23, 2017 · 10 comments

Comments

@irrigator
Copy link

irrigator commented May 23, 2017

I'm using the newest version of detox and RN and at first my test case looks like this:

await expect(element(by.id('status_text'))).toNotExist();
await element(by.id('fetch_status_button')).tap();
await expect(element(by.id('status_text'))).toHaveText('status: 200');

Problem 1: The tap action will trigger a network request and when that request succeeds the UI will show a Text component containing "status: 200". According to the doc of waitFor, "In most cases, tests should be automatically synchronized with the app.", it seems to me here I can use expect instead of waitFor and the runner will wait for the request to complete. However, it doesn't and the test case fails. So I change expect to waitFor.

Problem 2: This time it does wait for the request. However, I get "TypeError: waitFor(...).toHaveText is not a function". If I change toHaveText to toBeVisible, everything works! So I guess maybe waitFor does not work with toHaveText yet?

@irrigator
Copy link
Author

Update

Seems like waitFor will pass any expectation! I change that code to

await expect(element(by.id('status_text'))).toNotExist();
await element(by.id('fetch_status_button')).tap();
await expect(element(by.id('whatever'))).toBeVisible();

And it passes!

@talkol
Copy link

talkol commented May 23, 2017

Several things.

  1. I'm not 100% sure the latest 44 works well. There's a new issue from yesterday about it. Can you try for now with RN 40 just to make sure until 44 is officially supported?

  2. In your updated example, the code doesn't have waitFor. It has expect. Are you sure you pasted the correct code?

  3. With waitFor, the syntax should not be:

await waitFor(element(by.id('whatever'))).toBeVisible();

It should be:

await waitFor(element(by.id('whatever'))).toBeVisible().withTimeout(2000);

I agree that it's confusing because people forget the waitTimeout at the end. We'll change the syntax so it's easier to understand.

@rotemmiz
Copy link
Member

I confirmed that RN 0.44 broke text/label matching in detox. We're on it, trying to fix. ID matching should work anyway.

Your examples don't use waitFor, they use expect , can you please fix them according to @talkol's suggestion and see if it the error persists?

@irrigator
Copy link
Author

irrigator commented May 24, 2017

@talkol @rotemmiz Thanks for your answers! Maybe I didn't make point clear. I do use waitFor after expect fails. The problem with waitFor is that it will pass any random matcher.

@rotemmiz
Copy link
Member

rotemmiz commented May 24, 2017

Hey @irrigator.
We have updated the documentation and (hopefully) made it clearer.
Please check https://github.com/wix/detox/blob/master/docs/APIRef.waitFor.md again.

BTW, RN44 is now supported in detox@5.0.9

@jeduden
Copy link

jeduden commented Jul 11, 2017

@rotemmiz Looked at the docs of waitFor withTimeout. should it raise an exception if the timeout expires and the condition hasn't been met ?
This case doesn't seem to be covered in the cases here :

@rotemmiz
Copy link
Member

rotemmiz commented Jul 11, 2017

Hey @jeduden,
You're right, waitFor doesn't raise anything.
This is due to am implementation constraint that we have with wrapping the original EarlGrey waitWithTimeout API. We recently updated the manual sync docs, and there is now a clearer explanation on what it actually does (and what it doesn't)

@jeduden
Copy link

jeduden commented Jul 12, 2017

@rotemmiz in the earl grey docs. the docs are specifying that NO is returned in this case. Is this also the case for withTimeout ? i.e. impossibleCondition().withTimeout(2000) === false ?

@rotemmiz
Copy link
Member

@jeduden no, we return nothing currently, I know it's broken, but until we have a small refactor in that area we can't return this value.

@simonracz
Copy link
Contributor

#218

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

No branches or pull requests

6 participants