提交 549e944a 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

feat(inject): 补充泛型示例及测试

上级 2816f8c9
......@@ -5,7 +5,8 @@
<text class="mt-10 num">num: {{num}}</text>
<text class="mt-10 obj">obj: {{JSON.stringify(obj)}}</text>
<text class="mt-10 arr">arr: {{JSON.stringify(arr)}}</text>
<text class="mt-10 fn">fn: {{(fn as () => string)()}}</text>
<text class="mt-10 arr-0">arr[0]: {{ arr[0]}}</text>
<text class="mt-10 fn">fn: {{fn?.()}}</text>
<text class="mt-10 has-injection-context">hasInjectionContext:
{{checkHasInjectionContextRes}}</text>
<button class="mt-10 check-has-injection-context-btn" @click="checkHasInjectionContext">check
......@@ -14,11 +15,11 @@
</template>
<script setup lang='uts'>
const msg = inject('msg')
const msg = inject<string>('msg')
const num = inject('num')
const obj = inject('obj')
const arr = inject('arr')
const fn = inject('fn')
const arr = inject<number[]>('arr', [99])
const fn = inject<() => string>('fn')
const checkHasInjectionContextRes = ref('')
......
......@@ -20,6 +20,10 @@ describe('组合式 API provide', () => {
expect(await arr.text()).toBe('arr: [1,2,3]')
const arr0 = await page.$('.arr-0')
expect(await arr0.text()).toBe('arr[0]: 1')
const fn = await page.$('.fn')
expect(await fn.text()).toBe('fn: hello')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册