Load function from support folder cypress - cypress

In my support folder I have a folder called action. In there is a file calles login-action.js. The code in this file looks like this:
class LoginActions{
login(usernameField, passwordField, username, password) {
cy.get(usernameField).first().type(username);
cy.get(passwordField).last().type(password);
}
}
export default new LoginActions();
Now I want to use this login function in a test
loginActions.login('[data-test=username]', '[data-test=password]', this.user.username, this.user.password);
This is how I call it in the test. But somehow this is not working. It says that login is undefined.

I don't think that you can export new object like you are doing, I usually export only the class like this:
export default LoginActions();
Do you import and create new object loginActions like this:
import LoginActions from '../../../support/pageObjects/{loginActionsPage}'
const loginActions = new LoginActions();
And after this you can:
loginActions.login('[data-test=username]', '[data-test=password]', this.user.username, this.user.password);

Related

Mocking out a function inside another function

I don't actually want 'anotherFunction' to execute.
But rather when it's called inside someFunction, to have it return a specific value rather than actually executing:
// Testing this function
export function someFunction(foo, bar): string {
// want to provide a mock result here
const baz = anotherFunction(foo, bar);
// do something unrelated
}
export function anotherFunction(quz, quux): any {
// do something unrelated
}
How would you go about this with jasmine? The examples I find all assume a class and then use:
// Can't use this as the method I'd like to "mock out" is not in a class
const spy = spyOn(someClass, 'aMethod');
I'm looking for something similar to the mock function in Jest. That documentation helps communicate my question better:
"Mock functions allow you to test the links between code by erasing the actual implementation of a function, ..."
But then something similar in Jasmine.
Try something like this:
import * as helpers from './file/where/anotherFunction/is';
...
spyOn(helpers, 'anotherFunction');
Check this link out.

How to call one method globally across components in react native

I have a method called submit() in one component like eg. leave.js.
I have declared all the router navigation in router.js component.
I have placed a button in leave component header which is in router.js to apply the leave.
Now, i want to call this method from the click event of the button which is placed in the header.
How can i call this method globally from another component.
Kindly help me with a solution.
Thanks in Advance,
Regards,
Janani
I have tried the below link but its not working for me.
https://github.com/kriasoft/react-starter-kit/issues/909
When you create and use a function file, it's very useful.
Example
let name = "name";
function setName(data) {
name = data
}
function getName() {
return name
}
export { setName, getName }
import {setName, getName } from "./functionpath"
componentWilmount(){
setName("John");
}
componentDidmount(){
const name = getName();
alert(name);
}

Apply MVC pattern in ES6 for invoking methods

I am using the Model-View-Controller framework to structure my files for readable, reusable, and refactorable purposes.
My goal is to invoke methods from two seperate classes while working with one class. In practice; I want to access the methods for example in file Model.js and View.js from Controller.js.
Previously in ES5 I've had one file called app.js that used the IIFE approach:
var View = (function(){
dump(){
console.log('Hello World');
}
});
var Model = (function(){
// Code goes here
});
var Controller = (function(viewCtrl, viewCtrl){
viewCtrl.dump(); // Invoke method from View
})(View, Model);
As shown above, I would like to do something similar in ES6 too.
import View from './View';
import Model from './Model';
class Controller {
dump(){
return viewCtrl.dump();
}
init(){
console.log('Application has started');
// Make a new object of the class { View, Model }
let view = new View();
let model = new Model();
}
}
export default Controller;
In my main.js:
import Controller from './Controller';
// Make a new object of the class Controller
let controller = new Controller();
// Instantiate App
controller.init();
console.log(
controller.dump()
);
But doing so in ES6 I get error: ReferenceError: viewCtrl is not defined in main.js.
I was thinking perhaps pass View.js and Model.js as arguments in a constructor inside the Controller.js in order to declare them. But I guess it might be a better solution that looks cleaner.
So what I am basically looking for is to apply the MVC pattern using ES6, any recommendations?
Passing the instances of View and Model to the constructor of Controller is a clean solution since this would fullfill the dependency-injection-pattern.
This way you get the ability to change the instances from outside which makes the Controller testable.
In a situation where View and Model where singletons you could export them as instances instead of classes like
View.js:
export default new View();
Controller.js:
import view from "./View";
...
view.dump()
Using this way you could spare the work of passing a model and a view to a Controller manually but that would also mean that you loose the ability to test Controller or to change parts of it, like the View. Since this is one of the best advantages of the MVC-pattern, I would not recommend to import singletons. Instead I would recommend to inject View and Model using a constructor.

Ember 2.16.x: Accessing Ember.Handlebars.Utils.escapeExpression with new import syntax

How does one access the Ember.Handlebars.Utils.escapeExpression function using the new import syntax in Ember 2.16.x and above?
The following code snippet comes from the Writing Helpers section of the Ember docs. (FYI, there are a couple of unrelated errors in the original, which I have cleaned up in the code below.)
import { helper } from "#ember/component/helper";
import Handlebars from "handlebars";
import { htmlSafe } from "#ember/string";
export function makeBold(param /*, ...rest*/ ) {
let value = Handlebars.Utils.escapeExpression(param);
return htmlSafe(`<b>${value}</b>`);
}
export default helper(makeBold);
If I use the code above, I get the following error:
Could not find module 'handlebars' imported from 'ember-app/helpers/make-bold'
As of right now the Handlebars.Utils.escapeExpression function is not yet exported by the New Module Imports (aka. RFC 176). You should keep using it from the Ember import for now:
import Ember from 'ember';
Ember.Handlebars.Utils.escapeExpression(...)
An open GitHub issue for this exists at https://github.com/ember-cli/ember-rfc176-data/issues/12
The guides page that you linked appears to be mistaken and we need to fix that particular snippet. Sorry about that!

Import Cardinality Mismatch Exception

I have a main app and a plugin. The main app is exporting an IHost object and the plugin is importing an IHost object. I ran mefx and it recognizes both of those. But when I do /causes on the plugin it gives me a ImportCardinalityMismatchException. My container sees the plugin, but when I call Me.container.getExports(of IController)() it doesn't return anything.
My Controller looks like this:
Class Controller
Implements IController
' ...
<Import()>
Public Property Host As Lazy(Of IHost)
' ...
End Class
I had to <ImportMany()> in my plugin. Then for the variable I was importing to I needed to make it IEnumerable(Of Lazy(Of IHost)) Or use Lazy(of IHost) if you want to do a <Import()>

Resources