Skip to content

Commit 142fe1d

Browse files
author
Jamie Stumme
committed
Add test for injection on composition api component.
1 parent 4c14b61 commit 142fe1d

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"test:types": "tsc -p packages/test-utils/types && tsc -p packages/server-test-utils/types"
3232
},
3333
"dependencies": {
34+
"@vue/composition-api": "^0.3.2",
3435
"babel-core": "^6.26.0",
3536
"babel-eslint": "^8.2.2",
3637
"babel-loader": "^7.1.3",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<template>
2+
<div>
3+
{{ fromMount }}
4+
</div>
5+
</template>
6+
7+
<script>
8+
import { createComponent, reactive, toRefs, onMounted, inject } from '@vue/composition-api';
9+
10+
export default createComponent({
11+
name: 'component-with-inject-composition',
12+
setup: () => {
13+
const fromMount = inject('fromMount');
14+
const setInBeforeCreate = 'created';
15+
16+
return {
17+
fromMount,
18+
setInBeforeCreate,
19+
}
20+
}
21+
});
22+
</script>

test/specs/mounting-options/provide.spec.js

+18
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { config } from '~vue/test-utils'
2+
import { createLocalVue } from '~vue/test-utils'
23
import ComponentWithInject from '~resources/components/component-with-inject.vue'
4+
import CompositionComponentWithInject from '~resources/components/component-with-inject-composition.vue'
35
import { injectSupported } from '~resources/utils'
46
import { describeWithShallowAndMount } from '~resources/utils'
57
import { itDoNotRunIf, itSkipIf } from 'conditional-specs'
8+
import VueCompositionApi from '@vue/composition-api'
69

710
describeWithShallowAndMount('options.provide', mountingMethod => {
811
let configProvideSave
@@ -86,6 +89,21 @@ describeWithShallowAndMount('options.provide', mountingMethod => {
8689
}
8790
)
8891

92+
itDoNotRunIf(
93+
!injectSupported,
94+
'injects in a composition api component',
95+
() => {
96+
const localVue = createLocalVue()
97+
localVue.use(VueCompositionApi)
98+
const wrapper = mountingMethod(CompositionComponentWithInject, {
99+
provide: { fromMount: '_' },
100+
localVue
101+
})
102+
103+
expect(wrapper.html()).to.contain('_')
104+
}
105+
)
106+
89107
it('config with function throws', () => {
90108
config.provide = () => {}
91109

yarn.lock

+12
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,13 @@
810810
source-map "^0.5.6"
811811
vue-template-es2015-compiler "^1.6.0"
812812

813+
"@vue/composition-api@^0.3.2":
814+
version "0.3.2"
815+
resolved "https://registry.yarnpkg.com/@vue/composition-api/-/composition-api-0.3.2.tgz#2d797028e489bf7812f08c7bb33ffd03ef23c617"
816+
integrity sha512-fD4dn9cJX62QSP2TMFLXCOQOa+Bu2o7kWDjrU/FNLkNqPPcCKBLxCH/Lc+gNCRBKdEUGyI3arjAw7j0Yz1hnvw==
817+
dependencies:
818+
tslib "^1.9.3"
819+
813820
"@webassemblyjs/[email protected]":
814821
version "1.4.3"
815822
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.4.3.tgz#3b3f6fced944d8660273347533e6d4d315b5934a"
@@ -9601,6 +9608,11 @@ trough@^1.0.0:
96019608
version "1.0.1"
96029609
resolved "https://registry.yarnpkg.com/trough/-/trough-1.0.1.tgz#a9fd8b0394b0ae8fff82e0633a0a36ccad5b5f86"
96039610

9611+
tslib@^1.9.3:
9612+
version "1.10.0"
9613+
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a"
9614+
integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==
9615+
96049616
96059617
version "0.0.0"
96069618
resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6"

0 commit comments

Comments
 (0)