Skip to content

Commit 8ff0244

Browse files
committed
(test): ensure jsonify can be set to false
- previously a bug made it so you couldn't set it to false - this option is an edge case that's mostly useful for certain storage engines like WebSQL, IndexedDB, etc that can actually handle non-string data - for localStorage, objects just get stored as '[object Object]' if they're not jsonified - might want to throw on jsonify = false and localStorage engine?
1 parent 1398eae commit 8ff0244

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

test/index.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ describe('basic persist options', () => {
2727
expect(getItem('user')).toStrictEqual(getSnapshot(user))
2828
})
2929

30+
it('shouldn\'t jsonify', async () => {
31+
const user = UserStore.create()
32+
await persist('user', user, {
33+
jsonify: false
34+
})
35+
36+
user.changeName('Joe') // fire action to trigger onSnapshot
37+
// if not jsonified, localStorage will store as '[object Object]'
38+
expect(window.localStorage.getItem('user')).toBe('[object Object]')
39+
})
40+
3041
it('should whitelist', async () => {
3142
const user = UserStore.create()
3243
await persist('user', user, {

0 commit comments

Comments
 (0)