angular.js/test/service/cookieStoreSpec.js
Misko Hevery 48697a2b86 refactor(injector): turn scope into a service
- turn scope into a $rootScope service.
- injector is now a starting point for creating angular application.
- added inject() method which wraps jasmine its/beforeEach/afterEach,
  and which allows configuration and injection of services.
- refactor tests to use inject() where possible

BREAK:
- removed angular.scope() method
2011-11-14 16:39:31 -08:00

30 lines
1 KiB
JavaScript

'use strict';
describe('$cookieStore', function() {
it('should serialize objects to json', inject(function($cookieStore, $browser, $rootScope) {
$cookieStore.put('objectCookie', {id: 123, name: 'blah'});
$rootScope.$digest();
expect($browser.cookies()).toEqual({'objectCookie': '{"id":123,"name":"blah"}'});
}));
it('should deserialize json to object', inject(function($cookieStore, $browser) {
$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', inject(function($cookieStore, $browser, $rootScope) {
$cookieStore.put('gonner', { "I'll":"Be Back"});
$rootScope.$digest(); //force eval in test
$browser.poll();
expect($browser.cookies()).toEqual({'gonner': '{"I\'ll":"Be Back"}'});
$cookieStore.remove('gonner');
$rootScope.$digest();
expect($browser.cookies()).toEqual({});
}));
});