|
1 | 1 | import { compileToFunctions } from 'vue-template-compiler'
|
2 | 2 | import ComponentWithProps from '~resources/components/component-with-props.vue'
|
3 |
| -import { describeWithShallowAndMount } from '~resources/utils' |
| 3 | +import { |
| 4 | + describeWithShallowAndMount, |
| 5 | + itSkipIf, |
| 6 | + functionalSFCsSupported |
| 7 | +} from '~resources/utils' |
4 | 8 |
|
5 | 9 | describeWithShallowAndMount('props', (mountingMethod) => {
|
6 | 10 | it('returns true if wrapper has prop', () => {
|
@@ -32,6 +36,30 @@ describeWithShallowAndMount('props', (mountingMethod) => {
|
32 | 36 | expect(wrapper.props()).to.eql({ prop1: {}, prop2: 'val2' }) // fail
|
33 | 37 | })
|
34 | 38 |
|
| 39 | + itSkipIf(!functionalSFCsSupported(), |
| 40 | + 'works correctly a functional component', () => { |
| 41 | + const FunctionalComponent = { |
| 42 | + render: h => h('div'), |
| 43 | + functional: true, |
| 44 | + props: ['prop1'] |
| 45 | + } |
| 46 | + const TestComponent = { |
| 47 | + template: '<div><functional-component /></div>', |
| 48 | + components: { FunctionalComponent } |
| 49 | + } |
| 50 | + const prop1 = 'some prop' |
| 51 | + const wrapper = mountingMethod(TestComponent, { |
| 52 | + propsData: { |
| 53 | + prop1 |
| 54 | + } |
| 55 | + }) |
| 56 | + if (mountingMethod.name === 'mount') { |
| 57 | + const message = '[vue-test-utils]: wrapper.props() cannot be called on a mounted functional component.' |
| 58 | + const fn = () => wrapper.find(FunctionalComponent).props() |
| 59 | + expect(fn).to.throw().with.property('message', message) |
| 60 | + } |
| 61 | + }) |
| 62 | + |
35 | 63 | it('throws an error if called on a non vm wrapper', () => {
|
36 | 64 | const compiled = compileToFunctions('<div><p /></div>')
|
37 | 65 | const p = mountingMethod(compiled).findAll('p').at(0)
|
|
0 commit comments