Recently I wrote a test in the large app that I work on for a view that used a UIViewControllerRepresentable with a toolbar modifier applied to it.
The test failed because it couldn't find the modifier even when searching the parent view for the accessibility identifier of the toolbar button. But, when I embedded the UIViewControllerRepresentable in a ZStack and applied the toolbar to the ZStack instead the test succeeded & the app still worked as expected. I wasn't trying to test other modifiers but it seemed like they were also duplicated in the output, so this could be an issue with any modifier applied to a UIViewControllerRepresentable. It seems like the UIViewControllerRepresentable is acting more like a Group than a View. I'm not sure if that is expected, but it would be great to be able to inspect a modifier that gets applied directly to the view instead of using the workaround.
Code Example
This is a min reproducible example of the view structure:
Recently I wrote a test in the large app that I work on for a view that used a
UIViewControllerRepresentable
with a toolbar modifier applied to it.The test failed because it couldn't find the modifier even when searching the parent view for the accessibility identifier of the toolbar button. But, when I embedded the
UIViewControllerRepresentable
in aZStack
and applied the toolbar to theZStack
instead the test succeeded & the app still worked as expected. I wasn't trying to test other modifiers but it seemed like they were also duplicated in the output, so this could be an issue with any modifier applied to aUIViewControllerRepresentable
. It seems like the UIViewControllerRepresentable is acting more like aGroup
than aView
. I'm not sure if that is expected, but it would be great to be able to inspect a modifier that gets applied directly to the view instead of using the workaround.Code Example
This is a min reproducible example of the view structure:
And the associated test method which will fail if you copy & paste the code from above, but will succeed if you comment the
ZStack
back in:Here's a screenshot of the output when I run the test locally: