Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
koriwi committed Dec 17, 2018
1 parent 40e8b3b commit e3fd371
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions test/vuex-defaultstorage-asyncfilter.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Created by championswimmer on 23/07/17.
*/

import { assert, expect, should } from 'chai'
import Vue from 'vue'
import { Store } from 'vuex'
import Vuex from 'vuex'
import VuexPersistence from '..'

Vue.use(Vuex)
const vuexPersist = new VuexPersistence()
vuexPersist.filter = async (mutation) => (mutation.type === 'dogBark')
console.log((vuexPersist.storage as Storage).getItem('vuex') as string)
const store = new Store<any>({
state: {
dog: {
barks: 0
},
cat: {
mews: 0
}
},
mutations: {
dogBark(state) {
state.dog.barks++
},
catMew(state) {
state.cat.mews++
}
},
plugins: [vuexPersist.plugin]
})
const getSavedStore = () => JSON.parse((vuexPersist.storage as Storage).getItem('vuex') as string)

describe('Storage: Default Storage, Test: reducer, async-filter; Strict Mode: OFF', () => {
it('should persist reduced state', async () => {
store.commit('dogBark')
await ptimeout() // wait for store.commit
expect(getSavedStore().dog.barks).to.equal(1)
store.commit('catMew')
//noinspection TsLint
expect(getSavedStore().cat.mews).to.equal(0)
})
})

function ptimeout(ms = 10){
return new Promise((resolve, reject) => {
setTimeout(() => resolve(), ms)
})
}

0 comments on commit e3fd371

Please sign in to comment.