How can I access detox element matchers in custom helpers? - react-native

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?

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.

Related

How can I mock a nested 'this' function in Jest for Vue?

I'm testing a Vue component which is outside a normal Vue project structure (so for the purposes of this question it can be imagined as a standalone .vue file).
In the mounted() lifecycle hook I am calling a function which follows the following format:
this.$parent.$someValue.$getSomeData();
This would ordinarily be passed down the context when the file is in its proper place, but as it is standalone, how do I mock this with Jest?
I've tried adding it into mocks when mounting, spyOn and directly assigning it, such as by using wrapper.vm.$parent.$someValue.$getSomeData = jest.fn().mockReturnValue('');

In TestCafe Studio, how can I import/reference selectors/functions/custom scripts defined in one fixture into another?

If I define a selector or function in one test, can I access it in another test or a test in another file/fixture? Similarly, is there a way to implement page models and for tests to use selectors defined within page?
TestCafe Studio does not allow sharing selectors and functions defined via the "Define Element Selector" and "Define Function" actions in codeless testing. However, you can import selectors using the Run TestCafe Script action.
For example:

How do I create an instance for this package with Vue?

I'm trying to use this logging package I found in my Vue Project. https://github.com/xpl/ololog
I want to be able to use the logger in my whole project and all my components. Do I have to import the package in every single component I want to use it in or is there a way to make it global?
How can I make an instance for it? Sorry, I am confused about this. Thank you.
You can either:
A. Import the logger on every component
B. Add an instance property to make the log function accessible to all components:
// When you initialize your Vue app
Vue.prototype.$log = myLogFunction
// Now $log is available on all Vue instances via `this`
this.$log("my log");
A is more explicit, B is more convenient.

Should I be using Vue Mixins, "extends" or Vuex to share a method across all my components?

I want to have a Vue method that can be imported and used by any one of my Vue components. This method's job will be to handle exceptions passed to it (shown below).
handleException(err) {
console.error(err);
// send exception to error logging service
// do some other error-related stuff.
}
As far as I know, there are three main ways to accomplish this (please enlighten me if there are more ways that I am not aware of):
Have the method within a Vue Mixin and import this into any components that need the method.
Create a component containing the handleException method and use the "extends" keyword to import the template. (Pretty similar approach to Mixins approach).
Have the method in Vuex (as an action), which will allow me to call the method from any component using this.$store.dispatch...
For my use case, what is the best approach and why?

How can I access the WebDriver module from within an AcceptanceTester?

I have a test, where I an trying to change the configuration:
$this->getModule('WebDriver')->_reconfigure([...]);
This shows what I am trying to do under "Dynamic Configration": http://codeception.com/docs/06-ReusingTestCode#.VnXNjq6rTUI
Edit:
It appears that I have to call this on the moduleContainer, but this is located at:
$I->scenario->test->moduleContainer->getModule('WebDriver')->_getConfig('url');
However $test is under private access, and there is no getTest() method.
Documentation says: You may call it from a helper class and pass in all the fields you want to change.
Add reconfigure method to your Acceptance helper and call it from your test.