Search code examples
react-nativedetox

How can I access detox element matchers in custom helpers?


I am looking to access the element and by variables which are globally available in my test, but when I try to call them from a helper module required/imported by the test I get an undefined error. How can I import these variables directly?


Solution

  • Make sure detox.init() call happens earlier than you access those variables (element, by) because init method is the actual place where Detox globally exposes them.

    After you call await detox.init(<your options>), you'll be able to initialize your helpers.