angular.js/test/service/cookieStoreSpec.js
Misko Hevery 8f0dcbab80 feat(scope): new and improved scope implementation
- Speed improvements (about 4x on flush phase)
- Memory improvements (uses no function closures)
- Break $eval into $apply, $dispatch, $flush
- Introduced $watch and $observe

Breaks angular.equals() use === instead of ==
Breaks angular.scope() does not take parent as first argument
Breaks scope.$watch() takes scope as first argument
Breaks scope.$set(), scope.$get are removed
Breaks scope.$config is removed
Breaks $route.onChange callback has not "this" bounded
2011-08-02 01:00:03 +02:00

41 lines
1.1 KiB
JavaScript

'use strict';
describe('$cookieStore', function() {
var scope, $browser, $cookieStore;
beforeEach(function() {
scope = angular.scope();
$cookieStore = scope.$service('$cookieStore');
$browser = scope.$service('$browser');
});
afterEach(function(){
dealoc(scope);
});
it('should serialize objects to json', function() {
$cookieStore.put('objectCookie', {id: 123, name: 'blah'});
scope.$flush();
expect($browser.cookies()).toEqual({'objectCookie': '{"id":123,"name":"blah"}'});
});
it('should deserialize json to object', function() {
$browser.cookies('objectCookie', '{"id":123,"name":"blah"}');
$browser.poll();
expect($cookieStore.get('objectCookie')).toEqual({id: 123, name: 'blah'});
});
it('should delete objects from the store when remove is called', function() {
$cookieStore.put('gonner', { "I'll":"Be Back"});
scope.$flush(); //force eval in test
$browser.poll();
expect($browser.cookies()).toEqual({'gonner': '{"I\'ll":"Be Back"}'});
$cookieStore.remove('gonner');
scope.$flush();
expect($browser.cookies()).toEqual({});
});
});