forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparentComponent.spec.js
35 lines (33 loc) · 1.1 KB
/
parentComponent.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
34
35
import { describeWithMountingMethods } from '~resources/utils'
describeWithMountingMethods('options.parentComponent', mountingMethod => {
it('mounts component with $parent set to options.parentComponent', () => {
const Parent = {
data: () => ({
customName: 'Parent Name'
})
}
const TestComponent = {
template: '<div>{{$parent.customName}}</div>'
}
const wrapper = mountingMethod(TestComponent, {
parentComponent: Parent
})
const HTML = mountingMethod.name === 'renderToString'
? wrapper
: wrapper.html()
expect(HTML).to.contain('Parent Name')
})
it('validates parentComponent option', () => {
;['str', 123, [], () => {}].forEach(invalidParent => {
const TestComponent = {
template: '<div>{{$parent.customName}}</div>'
}
const fn = () => mountingMethod(TestComponent, {
parentComponent: invalidParent
})
const message = '[vue-test-utils]: options.parentComponent should be a valid Vue component options object'
expect(fn).to.throw()
.with.property('message', message)
})
})
})