jackmellis / mock-vuex Goto Github PK
View Code? Open in Web Editor NEWA Mock version of Vuex to make unit testing easier
License: MIT License
A Mock version of Vuex to make unit testing easier
License: MIT License
Previously store.assert would not throw an error. Now, when.reject will throw an error instead of rejecting. I think the best thing to do is to do the fijdMatchingReponse call synchronously, then call the call back asynchronously
First of all thank you for doing this - we definitely need something like arnaudbenard.com/redux-mock-store/ for Vue/Vuex.
Question: What is the practical difference with using a normal Vuex store?
store = new Vuex.Store({
state,
actions,
getters,
});
Speed & the helper methods I guess? But isn't re-creating your actions / mutations / state in tests a bit of an overhead - cheating? (I understand you're arguing that sometimes you wanna test pure component functionality without bothering with the store which is probably a legit argument but just to see if there's something else)
again thank you!
If you create a store with a null or array property i.e.
mockStore({
list : [],
thing : null
});
it tries to create a module from these properties, resulting in cannot access property of null
etc.
Change create.js line 9 to:
if (Object.prototype.toString.call(v) === '[object Object]'){
Blocking Vuenit 0.5
For namespaced store modules, vuex getters receive 4 arguments: (state, getters, rootState, rootGetters)
. It appears that the rootGetters
argument is being omitted.
mock-vuex automatically namespaces modules, but vuex allows you to create modules without their own namespace.
mock-vuex should namespace modules by default, but if namespace is false, do not namespace the module.
mock({
mutations : {
thing(){}
},
actions : {
thing(){}
}
})
I don't understand why this simple mutation fails to run in my Vuecli environment; but works perfectly from the example
Does Vuenit not work outside of ava?
import { mockStore } from 'vuenit'
// my test
const $store = mockStore({
common: {
state: {
loaded: true
},
mutations: {
why (state, payload) {
state.loaded = payload
console.log('called') // this never fires...
}
}
}
})
// straight from the example
const $store2 = mockStore({
things: {
state: {
things: []
},
getters: {},
mutations: {
ADD_THING(state, payload){
console.log('called!', state, payload) // neither does this
state.things.push(payload)
}
},
actions: {
addThing({state, commit}, payload){
commit('ADD_THING', payload)
return payload
}
}
}
})
describe('Http Service/Interceptors', () => {
it('on a request, should trigger a loading state', () => {
// interceptor.request($store)({})
$store.commit('why', false)
$store2.commit('ADD_THING', {})
console.log($store.state.common.loaded) // true — should be false
console.log($store2.state.things.length) // undefined
})
})
Using standard Vuecli webpack setup. Only added vuenit.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.