Skip to content

Commit 764774d

Browse files
committed
test: add test case for mapGetters in setComputed
closes #176
1 parent 35259c5 commit 764774d

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

test/unit/specs/mount/Wrapper/setComputed.spec.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { compileToFunctions } from 'vue-template-compiler'
2-
import { mount } from '~vue-test-utils'
2+
import { mount, createLocalVue } from '~vue-test-utils'
3+
import Vuex, { mapGetters } from 'vuex'
34
import ComponentWithComputed from '~resources/components/component-with-computed.vue'
45
import ComponentWithWatch from '~resources/components/component-with-watch.vue'
56

@@ -54,6 +55,34 @@ describe('setComputed', () => {
5455
expect(wrapper.vm.b).to.equal(3)
5556
})
5657

58+
it('works correctly with mapGetters', () => {
59+
const localVue = createLocalVue()
60+
localVue.use(Vuex)
61+
const store = new Vuex.Store({
62+
getters: {
63+
someGetter: () => false
64+
}
65+
})
66+
const TestComponent = {
67+
computed: {
68+
...mapGetters([
69+
'someGetter'
70+
]),
71+
placeholder () {
72+
return this.someGetter
73+
? 'someGetter is true'
74+
: 'someGetter is false'
75+
}
76+
}
77+
}
78+
const wrapper = mount(TestComponent, {
79+
localVue,
80+
store
81+
})
82+
wrapper.setComputed({ someGetter: true })
83+
expect(wrapper.vm.placeholder).to.equal('someGetter is true')
84+
})
85+
5786
it('throws an error if node is not a Vue instance', () => {
5887
const message = 'wrapper.setComputed() can only be called on a Vue instance'
5988
const compiled = compileToFunctions('<div><p></p></div>')

0 commit comments

Comments
 (0)