6

I have a simple service that sets cookies in angular, but there's no obvious way to test that they've been set in an end-to-end test.

The code to test is as simple as

var splashApp = angular.module('splashApp', ['ngCookies']);
splashApp.controller('FooterController', function ($location, $cookies) {
    $cookies.some_cookie = $location.absUrl();
});

But I can't find any docs on how to test. Here's what I have found:

I've also tried

angular.scenario.dsl('cookies', function() {
  var chain = {};
  chain.get = function(name) {
    return this.addFutureAction('get cookies', function($window, $document, done) {
      var injector = $window.angular.element($window.document.body).inheritedData('$injector');
      var cookies = injector.get('$cookies');
      done(null, cookies);
    });
  };
  return function() {
    return chain;
  }
});

But this returns only the cookies for the parent browser, not the page I want to test.

Any examples on how to do this?

Community
  • 1
  • 1
  • I'd assume that you're doing something with the cookies, maybe changing a CSS class, in your program - anything that effectively binds the value of the cookie to something external. Try testing that instead? – jclancy Jul 28 '13 at 19:00
  • I'm not, actually. The cookies are stored at some point in the session, then they're sent (automatically) to the server along with a POST request. There's no UI change because of cookies, unfortunately. – Darrell Silver Jul 30 '13 at 02:03
  • Have you read this? http://pastie.org/4758669 – jclancy Jul 30 '13 at 02:05

1 Answers1

0

It seems like you need to use PhantomJS.

PhantomJS is a headless WebKit scriptable with a JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG. --PhantomJS website

It has support for custom cookies in its API. In terms of testing, this is probably your best choice. You might also want to look at CasperJS to help test page navigation.

saada
  • 2,612
  • 3
  • 27
  • 33