fix(cookieReader): safely access $document so it can be mocked#11388
fix(cookieReader): safely access $document so it can be mocked#11388shahata wants to merge 1 commit intoangular:masterfrom shahata:cookies-mock-document
Conversation
|
I'm really not sure that this is the right way to solve this. I'm thinking it might be a good idea to have some mock implementation of |
|
@petebacondarwin probably comes up with a good idea how to solve this, he always does :) |
src/ng/cookieReader.js
Outdated
There was a problem hiding this comment.
I think this is probably overkill. If the developer mocks out window and doesn't include a document then lots of stuff is going to break. Instead, how about we simply do
lastCookieString = rawDocument.cookie || '';In the function below.
There was a problem hiding this comment.
actually this is the only place that breaks, you can mock out $window and not include $document. See https://github.com/angular/angular.js/blob/master/test/ng/windowSpec.js
There was a problem hiding this comment.
I can also do something like this, if you prefer:
rawDocument = $document[0] || {};
lastCookieString = rawDocument.cookie || '';There was a problem hiding this comment.
Ugh! Mocking window without a document is surely crazy juice!
OK let's go with this version:
rawDocument = $document[0] || {};
lastCookieString = rawDocument.cookie || '';|
LGTM - feel free to merge |
Closes #11373