0

I have my test setup using jest and detox (@e2e)

Issue is, despite seemingly properly importing @testing-lib/jest-dom, I can't seem to use the toHaveAttribute() matcher as I should be able to.


Inside my spec.js file:

import { toHaveAttribute } from '@testing-library/jest-dom/matchers'
import '@testing-library/jest-dom/extend-expect'

expect.extend({
  toHaveAttribute,
})

// ... tests here

However, when running my tests, I get the following error:

TypeError: expect(...).toHaveAttribute is not a function

enter image description here

Samuel Hulla
  • 6,617
  • 7
  • 36
  • 70

1 Answers1

1

Native development is not DOM. Detox implements its own expectation API, which is routed to the appropriate platform's native implementation, and toHaveAttribute() is not implemented. We have no concrete plans currently to support this, but we will consider in the future, once a planned rewrite of the iOS side is completed.

Léo Natan
  • 56,823
  • 9
  • 150
  • 195
  • given this, is there currently any way you expect users to check for values in checkboxes / radio buttons? As of now I'm struggling to think of anything with the current detox toolset, other than creating a hidden text that acts as a `state` text-checkbox, which will be checked for value. – Samuel Hulla Mar 03 '20 at 13:19
  • I think toHaveValue should work. In any case, we will have a way to pull attributes into JS in the future. – Léo Natan Mar 03 '20 at 13:39