Open GoogleCodeExporter opened 8 years ago
It seems like that the "sessionStorage" can not be recognized in JsUnit.
So, it should be MOCKed in JsUnit test.
The mock method is like :
---------------------------------
var mockup = function() {
var table = {};
return {
getItem : function(key) {
return table[key];
},
setItem : function(key, value) {
table[key] = value;
},
clear : function() {
table = {};
}
};
}();
Object.defineProperty(window, 'sessionStorage', {
value : mockup
});
-------------------------------------------
Refrence to this page:
http://stackoverflow.com/questions/9428210/how-to-deal-with-sessionstorage-local
ly-in-ff-for-testing
Original comment by sunys...@gmail.com
on 13 Sep 2012 at 6:48
And by using this method , the PhoneGap object "device" can also be moked :
----------------------------------------------------------
var mockup = function() {
return {
exitApp : function(key) {
return true;
}
};
}();
Object.defineProperty(window, 'device', {
value : mockup
});
-------------------------------------------------------------------
Original comment by sunys...@gmail.com
on 13 Sep 2012 at 6:59
and so XMLHTTPRequest or XMLHTTPResponse:
-----------------------------------------------------------------
var mockupReqst = function() {
var table = {"set-cookie" : "mock cookie"};
return {
getAllResponseHeaders : function() {
return table;
},
getResponseHeader : function(key) {
return table[key];
},
getItem : function(key) {
return table[key];
},
setItem : function(key, value) {
table[key] = value;
},
clear : function() {
table = {};
}
};
}();
Object.defineProperty(window, 'XMLHttpRequest', {
value : mockupReqst
});
var mockupResp = function() {
var table = {"set-cookie" : "mock cookie"};
return {
getAllResponseHeaders : function() {
return table;
},
getResponseHeader : function(key) {
return table[key];
},
getItem : function(key) {
return table[key];
},
setItem : function(key, value) {
table[key] = value;
},
clear : function() {
table = {};
}
};
}();
Object.defineProperty(window, 'XMLHttpResponse', {
value : mockupResp
});
-----------------------------------------------------------------
Original comment by sunys...@gmail.com
on 13 Sep 2012 at 7:00
Is there anything to do about it in Closure?
Original comment by pall...@google.com
on 19 Oct 2012 at 10:25
Original issue reported on code.google.com by
sunys...@gmail.com
on 12 Sep 2012 at 9:49