forked from vuejs/vue-test-utils
/
setData.spec.js
33 lines (29 loc) 路 1.31 KB
/
setData.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { compileToFunctions } from 'vue-template-compiler'
import ComponentWithVIf from '~resources/components/component-with-v-if.vue'
import { describeWithShallowAndMount } from '~resources/utils'
describeWithShallowAndMount('setData', mountingMethod => {
it('sets component data and updates nested vm nodes', async () => {
const wrapper = mountingMethod(ComponentWithVIf)
const componentArr = wrapper.findAll(ComponentWithVIf)
expect(componentArr.at(0).findAll('.child.ready').length).toEqual(0)
await componentArr.setData({ ready: true })
expect(componentArr.at(0).findAll('.child.ready').length).toEqual(1)
})
it('throws an error if node is not a Vue instance', () => {
const message =
'[vue-test-utils]: wrapper.setData() can only be called on a Vue instance'
const compiled = compileToFunctions('<div><p></p></div>')
const wrapper = mountingMethod(compiled)
const fn = () => wrapper.findAll('p').setData({ ready: true })
expect(fn).toThrow(message)
})
it('throws error if wrapper array contains no items', () => {
const compiled = compileToFunctions('<div />')
const message = '[vue-test-utils]: setData cannot be called on 0 items'
const fn = () =>
mountingMethod(compiled)
.findAll('p')
.setData('p')
expect(fn).toThrow(message)
})
})