Skip to content

Commit

Permalink
(test): ensure jsonify can be set to false
Browse files Browse the repository at this point in the history
- 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?
  • Loading branch information
agilgur5 committed Nov 19, 2019
1 parent 1398eae commit 8ff0244
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ describe('basic persist options', () => {
expect(getItem('user')).toStrictEqual(getSnapshot(user))
})

it('shouldn\'t jsonify', async () => {
const user = UserStore.create()
await persist('user', user, {
jsonify: false
})

user.changeName('Joe') // fire action to trigger onSnapshot
// if not jsonified, localStorage will store as '[object Object]'
expect(window.localStorage.getItem('user')).toBe('[object Object]')
})

it('should whitelist', async () => {
const user = UserStore.create()
await persist('user', user, {
Expand Down

0 comments on commit 8ff0244

Please sign in to comment.