Unit testing a Vuex store
summary
Three approaches: no tests for tiny projects, unit-test each part with Jest (mutations called with a fake state, getters called with a fake state, actions mocked) and test a whole store instance. Uses jest.mock/jest.fn to stub the fetchData API so the fetchItems action commits setItems with mocked items, and uses createLocalVue plus a createStoreConfig function so each test gets fresh state. Example assertion: displayItems returns items 20–39 when page = 2 out of 42.
AI-written summary · about
chapters (8)
- 0:00Start
- 1:20write a unit test using a framework
- 7:06test each of the store parts
- 7:17write unit tests for each of these functions
- 8:43write unit tests for a simple mutation
- 18:25install the us on a local view constructor
- 23:10refactor without updating your tests
- 23:55split up your unit tests and your end-to-end tests








