-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Matching by.ID on conditionally rendered elements after a tap doesn't seem to work only on Text elements (iOs) #4051
Comments
@Omicron-Z if you wrap <View testID="world_text"><Text>...World!!</Text></View> |
Actually, before doing so, could you first run |
@asafkorem fyi |
Hi d4vidi, first of all thanks a lot for your answers.
It does, actually I was already trying to do that test and that's also why I opened an Issue, because it seemed such an unintended behaviour and not a generic synchronization issue. This section of the test app: {hello && <View testID="hello_text_view"><Text>Hello...</Text></View>} Is covered successfully by this test: it('should show hello screen after tap', async () => {
const helloButton = await element(by.id('hello_button'));
await helloButton.tap();
const helloText = await element(by.id('hello_text_view'));
await expect(helloText).toExist();
}); So I would have expected the same to work without the View wrapper.
Done, here are the results (I had to zip them or Github won't allow the upload): |
I suspected this and it's likely right - |
@d4vidi Thanks for the detailed follow-up, much appreciated. I tried a couple of other approaches, just for completion. The other was wrapping the text with a view outside the conditionally rendered part. So, something like this: {'\n'}
{/* See issue https://github.com/wix/Detox/issues/4051 for further details */}
<View>{world && <Text testID="world_text">...World!!</Text>}</View>
{'\n'} That was enough to make the test pass. So, to summarize, doing either of these workarounds <Button
testID="hello_button"
title="HELLO..."
onPress={() => setHello(!hello)}
/>
{'\n'}
{hello && (
<View testID="hello_text_view">
<Text>Hello...</Text>
</View>
)}
{'\n'}
<Button
testID="world_button"
title="WORLD!"
onPress={() => setWorld(!world)}
/>
{'\n'}
{/* See issue https://github.com/wix/Detox/issues/4051 for further details */}
<View>{world && <Text testID="world_text">...World!!</Text>}</View>
{'\n'} Works and allows tests to behave as expected. It might be worthy to add some kind of warning or disclaimer in the official docs. Thanks a lot for clarification. |
Interesting case @Omicron-Z, I'm glad it's resolved (@d4vidi You are the best! 👑) @Omicron-Z We will consider your suggestion to add a disclaimer, though this bug / bug-by-design originates from react native. |
What happened?
Greetings everyone. I have been trying Detox on a clean react-native app on iOs, and I've run into an issue with the Matchers, both with detox 20.8 and with 20.9.
Specifically, attempting to match by testID on a Text node which is rendered dynamically (the usual conditional rendering according to React status) after a tap doesn't work. However, the same match by testID does work on View nodes (in the same circumstances) or Text nodes statically rendered.
Put it in another way, trying to do:
Works. However, if I try to do the same on a
I run into the following error:
I also tried with
And in this case i get a timeout, which I haven't been able to solve. It seems excessive, a 5second out of sync error for a simple device tap. And why would it work with a View but not with a Text?
You'll find the detailed code and logs below.
I might be missing something, but I've followed the tutorial, the documentation and the synch issue help page and couldn't get why it shouldn't work.
What was the expected behaviour?
I expect matchers to be able to select elements by testID regardless of them being Text or View elements, and to be able to do so without going in timeout after a single tap.
So, I'd expect the tests detailed above and below to be able to pass.
Was it tested on latest Detox?
Did your test throw out a timeout?
Help us reproduce this issue!
Example code of my React Native starting app for this test:
These three tests are passing correctly:
However, this other never passes, in any way or form:
In what environment did this happen?
Detox version: 20.9.0
React Native version: 0.70.7
Has Fabric (React Native's new rendering system) enabled: no
Node version: 16.20.0
Device model: iPhone 14
iOS version: 16.2
macOS version: 13.3.1
Xcode version: 14.2
Test-runner (select one): jest
Detox logs
detox.log
Device logs
device.log
More data, please!
Test Start Screenshot:
Test Failure Screenshot:
The text was updated successfully, but these errors were encountered: