|
1 | 1 | import { config } from '~vue/test-utils'
|
| 2 | +import { createLocalVue } from '~vue/test-utils' |
2 | 3 | import ComponentWithInject from '~resources/components/component-with-inject.vue'
|
| 4 | +import CompositionComponentWithInject from '~resources/components/component-with-inject-composition.vue' |
3 | 5 | import { injectSupported } from '~resources/utils'
|
4 | 6 | import { describeWithShallowAndMount } from '~resources/utils'
|
5 | 7 | import { itDoNotRunIf, itSkipIf } from 'conditional-specs'
|
| 8 | +import VueCompositionApi from '@vue/composition-api' |
6 | 9 |
|
7 | 10 | describeWithShallowAndMount('options.provide', mountingMethod => {
|
8 | 11 | let configProvideSave
|
@@ -58,6 +61,23 @@ describeWithShallowAndMount('options.provide', mountingMethod => {
|
58 | 61 | }
|
59 | 62 | )
|
60 | 63 |
|
| 64 | + itDoNotRunIf( |
| 65 | + !injectSupported || mountingMethod.name === 'renderToString', |
| 66 | + 'supports setup in composition api component', |
| 67 | + () => { |
| 68 | + if (!injectSupported) return |
| 69 | + |
| 70 | + const localVue = createLocalVue() |
| 71 | + localVue.use(VueCompositionApi) |
| 72 | + const wrapper = mountingMethod(CompositionComponentWithInject, { |
| 73 | + provide: { fromMount: '_' }, |
| 74 | + localVue |
| 75 | + }) |
| 76 | + |
| 77 | + expect(wrapper.vm.setInSetup).to.equal('created') |
| 78 | + } |
| 79 | + ) |
| 80 | + |
61 | 81 | itSkipIf(
|
62 | 82 | mountingMethod.name === 'renderToString',
|
63 | 83 | 'injects the provide from the config',
|
@@ -86,6 +106,21 @@ describeWithShallowAndMount('options.provide', mountingMethod => {
|
86 | 106 | }
|
87 | 107 | )
|
88 | 108 |
|
| 109 | + itDoNotRunIf( |
| 110 | + !injectSupported, |
| 111 | + 'injects in a composition api component', |
| 112 | + () => { |
| 113 | + const localVue = createLocalVue() |
| 114 | + localVue.use(VueCompositionApi) |
| 115 | + const wrapper = mountingMethod(CompositionComponentWithInject, { |
| 116 | + provide: { fromMount: '_' }, |
| 117 | + localVue |
| 118 | + }) |
| 119 | + |
| 120 | + expect(wrapper.html()).to.contain('_') |
| 121 | + } |
| 122 | + ) |
| 123 | + |
89 | 124 | it('config with function throws', () => {
|
90 | 125 | config.provide = () => {}
|
91 | 126 |
|
|
0 commit comments