-
-
Notifications
You must be signed in to change notification settings - Fork 768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
localStorage throwing error: Should wrap property of object
#1129
Comments
I think this is a duplicate, see #1046. I think the fix was introduced in #1098. That is only present in the 1.17.5 release and the master branch. Retest using either. PS. Stubbing of localStorage is not possible across browsers. What might work in Chrome today fails in Firefox and might fail in the Chrome of tomorrow. Test using a higher abstraction and use DI. |
@fatso83 Thank you. I'll update to 1.17.5.
Test
The tests pass this way. You mentioned using a higher abstraction as DI. Can you share an example what you referred to? |
@umairwanclouds: re higher abstraction I was simply thinking of instead of directly interfacing with localStorage in your code, you create a thin abstraction layer. Say a function Storage(opts) {
if(opts.db){ this.db = opts.db }
else { this.db = window.localStorage; // default }
}
Storage.prototype = {
get : function(key) { return this.db.getItem(key); }
set : function(key,val) { return this.db.setItem(key, val); }
} Then you test against this abstraction, instead of at the lowest implementation level. describe('storage', function(){
it("should call the underlying db implementation's getItem", function() {
var dbStub = { getItem : sinon.stub(); }
var storage = new Storage(dbStub);
storage.getItem('foo');
assert.true(dbStub.getItem.calledOnce);
});
}); P.S. The code above is not testet, but should illustrate the point. |
@fatso83 Ah I see. That's much better. Thanks a lot. |
This is a piece of code in my
component JSX
that I am trying to test.So with this,
gives an error:
TypeError: Should wrap property of object
I've gone through this #1046 but I'm guessing this was fixed in the version I'm using.
At first I thought it was some personal implementation error because previously when I had to access
window
I had create a global object that mocked window:I tried this approach but, that isn't the root of my current problem as far as I think. I've traced back the error but so far no luck.
[Windows/Chrome]
The text was updated successfully, but these errors were encountered: