Skip to content

Instantly share code, notes, and snippets.

@F1LT3R
Last active August 29, 2015 14:27
Show Gist options
  • Save F1LT3R/be1d78916bc11b224550 to your computer and use it in GitHub Desktop.
Save F1LT3R/be1d78916bc11b224550 to your computer and use it in GitHub Desktop.
something.js
// In the app
app.factory('MyService', [function () {
return {
mydata: "Hello world!",
myfunc: function(a, b) {
return a+b;
}
}
}]);
// In the Protractor test
browser.executeScript(function() {
return angular.element(document).injector().get('MyService');
}).then(function(MyService){
console.log(MyService.mydata);
// logs: "Hello World!"
console.log(MyService.myfunc);
// logs: "{}"
MyService.myfunc(2, 2);
// "TypeError: object is not a function"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment