Skip to content

Instantly share code, notes, and snippets.

@juniorconte
Created September 29, 2013 09:02
Show Gist options
  • Save juniorconte/6750692 to your computer and use it in GitHub Desktop.
Save juniorconte/6750692 to your computer and use it in GitHub Desktop.
DSL Extend to manipulate Cookies on e2e tests from AngularJs
'use strict';
angular.scenario.dsl('cookies', function() {
var chain = {};
chain.set = function(name,value) {
return this.addFutureAction('set cookie', function($window, $document, done) {
var injector = $window.angular.element($window.document.body).inheritedData('$injector');
var cookies = injector.get('$cookies');
var root = injector.get('$rootScope');
cookies[name] = value;
root.$apply();
done();
});
};
chain.remove = function(name) {
return this.addFutureAction('remove cookie', function($window, $document, done) {
var injector = $window.angular.element($window.document.body).inheritedData('$injector');
var cookies = injector.get('$cookies');
var root = injector.get('$rootScope');
delete cookies[name];
root.$apply();
done();
});
};
chain.clear = function() {
return this.addFutureAction('clear cookies', function($window, $document, done) {
var injector = $window.angular.element($window.document.body).inheritedData('$injector');
var cookies = injector.get('$cookies');
var root = injector.get('$rootScope');
for (var name in cookies) {
delete cookies[name];
}
root.$apply();
done();
});
};
return function() {
return chain;
}
});
@juniorconte
Copy link
Author

Read more about e2e / Functional tests with AngularJS in https://docs.angularjs.org/guide/e2e-testing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment