From aa9c2131ebe2559e7c5ab3e4d66e0da66c2a5452 Mon Sep 17 00:00:00 2001 From: ktsn Date: Fri, 24 Feb 2017 14:26:23 +0900 Subject: [PATCH] Tweak testing docs to make consistent with code base --- README.md | 85 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 2c68426..6e39ac3 100644 --- a/README.md +++ b/README.md @@ -94,49 +94,62 @@ vm.increment() // increment immediately ``` ## Testing with vuex-local + Testing vuex-local module can be as easy as ordinary vuex module. Just getting the module by Component.local(). ```js -const module = App.local.call({name:'counterApp'});//use .call to inject a mock component -let {state,getters,actions,mutations} = module; +// Use `call` method to inject a mock component +const module = App.local.call({ name: 'counterApp' }) +const { state, getters, actions, mutations } = module ``` A full example here: + ```js -import App from '../App.vue'; - -describe('App Local Module',()=>{ - const module = App.local.call({name:'counterApp'});//use .call to inject a mock component - let {state, getters, actions, mutations} = module; - it('counter to be 0 initially',()=>{ - expect(state.count).to.be.equal(0); - const anotherModule = App.local.call({name:'counterApp'}); - expect(anotherModule.state.count).to.be.equal(0); - }); - it('return half',()=>{ - expect(getters.half({count:0})).to.be.equal(0); - expect(getters.half({count:-1})).to.be.equal(-0.5); - expect(getters.half({count:1})).to.be.equal(0.5); - }); - it('increment the counter in state',()=>{ - let state = {count:0}; - mutations.increment(state); - expect(state.count).to.be.equal(1); - mutations.increment(state); - expect(state.count).to.be.equal(2); - }); - it('increment after 1 second',function(done){ - this.timeout(1100); - let begin = Date.now(); - let commit = (mutationName)=>{ - expect(mutationName).to.be.equal('increment'); - expect(Date.now() - begin).to.be.above(900); - expect(Date.now() - begin).to.be.below(1100); - done(); - }; - actions.asyncIncrement({commit}); - }); -}); +import App from '../App.vue' + +describe('App Local Module', () => { + // Use `call` method to inject a mock component + const module = App.local.call({ name: 'counterApp' }) + const { state, getters, actions, mutations } = module + + it('counter to be 0 initially', () => { + expect(state.count).to.be.equal(0) + + const anotherModule = App.local.call({ name: 'counterApp' }) + expect(anotherModule.state.count).to.be.equal(0) + }) + + it('return half', () => { + expect(getters.half({ count: 0 })).to.be.equal(0) + expect(getters.half({ count: -1 })).to.be.equal(-0.5) + expect(getters.half({ count: 1 })).to.be.equal(0.5) + }) + + it('increment the counter in state', () => { + const state = { count: 0 } + + mutations.increment(state) + expect(state.count).to.be.equal(1) + + mutations.increment(state) + expect(state.count).to.be.equal(2) + }) + + it('increment after 1 second', done => { + this.timeout(1100) + const begin = Date.now() + + const commit = mutationName => { + expect(mutationName).to.be.equal('increment') + expect(Date.now() - begin).to.be.above(900) + expect(Date.now() - begin).to.be.below(1100) + done() + } + + actions.asyncIncrement({ commit }) + }) +}) ``` ## License