I have a code snippet in one of my JS files that looks like this:
// test/lib/UserHelper.js
'use strict';
var Firebase = require('firebase');
exports.createUser = function (email, password) {
browser.executeAsyncScript(function (done) {
var $firebaseSimpleLogin = angular.inject(['ng', 'firebase']).get('$firebaseSimpleLoging');
var firebaseRef = new Firebase('https://urltoapplication.firebaseio.com');
var auth = $firebaseSimpleLogin(firebaseRef);
auth.$createUser(email, password);
done();
});
};
When I try to call it within my test as shown below:
// test/settings/company.spec.js
'use strict';
var user = require('../lib/UserHelper');
describe('company specs', function () {
beforeEach(function () {
user.createUser('<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dbafbea8af9bafbea8aff5b8b4b6">[email protected]</a>', 'test');
});
});
The call to
user.createUser('<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2b5f4e585f6b5f4e585f05484446">[email protected]</a>', 'test');
in the beforeEach
callback fails with UnknownError: email is not defined
at auth.$createUser(email, password);
.
I am curious why the email
variable is not accessible in the callback function. Is there a way to pass arguments to the closing function that were initially passed to the createUser
function?
After consulting with Andres D., I found a solution that worked for me. Here is the updated code:
exports.createUser = function (data) {
browser.executeAsyncScript(function (data, done) {
var $firebaseSimpleLogin = angular.inject(['ng', 'firebase']).get('$firebaseSimpleLoging');
var firebaseRef = new Firebase('https://urltoapplication.firebaseio.com');
var auth = $firebaseSimpleLogin(firebaseRef);
auth.$createUser(data.email, data.password);
done();
}, data);
};