Thursday, February 25, 2016

The black hole in localStorage.setItem()

TL;DR

To fake some local storage data in Protractor E2E test, care about 2 things:
  • localStorage can not store Object directly, so you have to JSON.stringify it and then JSON.parse to get it back.
  • browser.executeScript actually returns a Promise, so you should JSON.parse the data received by its then function.

How to mock $httpBackend in protractor

Some say this is not a good idea since end-to-end test should be genuinely END-TO-END, not END-TO-itself, ......whatever, I just need it.

My solution is based on this post, but I got 2 problems which screwed me good.

Saturday, February 20, 2016

Angular bound model data not updated in the $on callback function

TL;DR

Using $timeout or $apply, or $evalAsync in the callback function of $on, if you need to handle some bound model and have to make sure you get it before or after it's updated

I met this one when I was trying to save map data from a google map view whenever user changes the map view.