4

I'm trying to debug some Detox tests, I've got some assertions like the following:

await expect(eventScreenMatcher.component).toExist();
await expect(eventScreenMatcher.toggleButton).toExist();
await expect(eventScreenMatcher.toggleButton).toHaveText('Add to schedule');

The button that I believe is the toggleButton is on screen and has the correct text Add to schedule. But Detox is failing on that last assertion.

How does Detox determine what the text is (does it just check that element) and is there a way to log what it thinks is there?

This is the output I currently get:

Expected: (with text: is "Add to schedule" and view has effective visibility=VISIBLE) Got: "ReactViewGroup{id=4605, visibility=VISIBLE, width=1300, height=139, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=android.view.ViewGroup$LayoutParams@34f98eb, tag=ToggleScheduleButton, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}

Ian
  • 33,605
  • 26
  • 118
  • 198

1 Answers1

1

Have you tried using the ‘getAttributes()’ method? It can be a little tricky sometimes but I think it would help solve your problem. https://wix.github.io/Detox/docs/api/actions-on-element/#getattributes

Then you could try something like

const buttonAttributes = await eventScreenMatcher.toggleButton.getAttributes();

await jestExpect(buttonAttributes.text).toBe('Add to Schedule');