提交 3a44faca 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

feat: 调整示例及测试,兼容 web 端

上级 1e272ee8
......@@ -12,7 +12,7 @@ describe('defineExpose', () => {
const fooNum = await page.$('#foo-num')
expect(await fooNum.text()).toBe('num from component Foo: 0')
const incrementBtn = await page.$('#increment-btn')
const incrementBtn = await page.$('.increment-btn')
await incrementBtn.tap()
expect(await fooNum.text()).toBe('num from component Foo: 1')
......
......@@ -3,7 +3,7 @@
<define-expose-foo ref='fooRef' />
<text id="foo-str" class="uni-common-mt">str from component Foo: {{fooStr}}</text>
<text id="foo-num" class="uni-common-mt">num from component Foo: {{fooNum}}</text>
<button id="increment-btn" class="uni-common-mt" @click="increment">trigger Foo increment</button>
<button class="increment-btn uni-panel-h-on" @click="increment">trigger Foo increment</button>
</view>
</template>
......
......@@ -4,7 +4,7 @@
<slot :msg="msg"></slot>
<slot name="footer" :arr="arr"></slot>
<text id="check-use-slots-res" class="uni-common-mt">check useSlots result: {{ checkUseSlotsRes }}</text>
<button id="check-use-slots-btn" class="uni-common-mt" @click="checkUseSlots">
<button class="check-use-slots-btn uni-common-mt" @click="checkUseSlots">
check useSlots
</button>
</view>
......
......@@ -14,12 +14,12 @@ describe('useSlots', () => {
expect(await slotContent.text()).toBe('default slot msg: default msg')
const slotFooter = await page.$('#slot-footer')
expect(await slotFooter.text()).toBe('footer slot arr: ["a","b","c"]')
expect((await slotFooter.text()).replaceAll('\n', '')).toBe('footer slot arr: ["a","b","c"]')
const checkUseSlotsRes = await page.$('#check-use-slots-res')
expect(await checkUseSlotsRes.text()).toBe('check useSlots result: false')
const checkUseSlotsBtn = await page.$('#check-use-slots-btn')
const checkUseSlotsBtn = await page.$('.check-use-slots-btn')
await checkUseSlotsBtn.tap()
expect(await checkUseSlotsRes.text()).toBe('check useSlots result: true')
......
......@@ -7,7 +7,7 @@
<text class="uni-common-mt arr">arr: {{arr}}</text>
<text class="uni-common-mt fn">fn: {{(fn as () => string)()}}</text>
<text class="uni-common-mt has-injection-context">hasInjectionContext:
{{checkHasInjectionContextRes}}</text>
{{checkHasInjectionContextRes}}</text>
<button class="uni-common-mt check-has-injection-context-btn" @click="checkHasInjectionContext">check hasInjectionContext</button>
</view>
</template>
......@@ -17,12 +17,15 @@
const num = inject('num')
const obj = inject('obj')
const arr = inject('arr')
const fn = inject('fn')
const fn = inject('fn')
const checkHasInjectionContextRes = ref('')
const checkHasInjectionContext = () => {
// TODO: web vue 版本低导致 hasInjectionContext 不支持, 待支持后调整
// #ifdef APP
checkHasInjectionContextRes.value = `${hasInjectionContext()}`
}
// #endif
}
checkHasInjectionContext()
</script>
\ No newline at end of file
......@@ -23,12 +23,14 @@ describe('provide-inject-hasInjectionContext', () => {
const fn = await page.$('.fn')
expect(await fn.text()).toBe('fn: hello')
const hasInjectionContext = await page.$('.has-injection-context')
expect(await hasInjectionContext.text()).toBe('hasInjectionContext: true')
if (process.env.uniTestPlatformInfo.startsWith('android')) {
const hasInjectionContext = await page.$('.has-injection-context')
expect(await hasInjectionContext.text()).toBe('hasInjectionContext: true')
const checkHasInjectionContextBtn = await page.$('.check-has-injection-context-btn')
await checkHasInjectionContextBtn.tap()
expect(await hasInjectionContext.text()).toBe('hasInjectionContext: false')
const checkHasInjectionContextBtn = await page.$('.check-has-injection-context-btn')
await checkHasInjectionContextBtn.tap()
expect(await hasInjectionContext.text()).toBe('hasInjectionContext: false')
}
})
})
\ No newline at end of file
......@@ -10,14 +10,17 @@ describe('customRef', () => {
const stateCount = await page.$('#state-count')
expect(await stateCount.text()).toBe('state.count: 0')
const incrementBtn = await page.$('#increment-btn')
const incrementBtn = await page.$('.increment-btn')
await incrementBtn.tap()
expect(await stateCount.text()).toBe('state.count: 0')
// TODO: web 暂不支持 triggerRef
if (process.env.uniTestPlatformInfo.startsWith('android')) {
const triggerRefBtn = await page.$('.trigger-ref-btn')
await triggerRefBtn.tap()
const triggerRefBtn = await page.$('#trigger-ref-btn')
await triggerRefBtn.tap()
expect(await stateCount.text()).toBe('state.count: 1')
expect(await stateCount.text()).toBe('state.count: 1')
}
})
})
\ No newline at end of file
<template>
<view class="page">
<text id="state-count">state.count: {{state['count']}}</text>
<button class="uni-common-mt" id="increment-btn" @click="increment">increment state.count</button>
<button class="uni-common-mt" id="trigger-ref-btn" @click="triggerRefState">triggerRef state</button>
<button class="uni-common-mt increment-btn" @click="increment">increment state.count</button>
<button class="uni-common-mt trigger-ref-btn" @click="triggerRefState">triggerRef state</button>
</view>
</template>
......
......@@ -17,14 +17,14 @@ describe('reactive', () => {
expect(await objNum.text()).toBe('obj.num: 0')
const objArr = await page.$('#obj-arr')
expect(await objArr.text()).toBe('obj.arr: ["a","b","c"]')
expect((await objArr.text()).replaceAll('\n', '')).toBe('obj.arr: ["a","b","c"]')
const updateBtn = await page.$('#update-btn')
const updateBtn = await page.$('.update-btn')
await updateBtn.tap()
expect(await count.text()).toBe('count: 2')
expect(await objStr.text()).toBe('obj.str: new str')
expect(await objNum.text()).toBe('obj.num: 2')
expect(await objArr.text()).toBe('obj.arr: ["a","b","c","d"]')
expect((await objArr.text()).replaceAll('\n', '')).toBe('obj.arr: ["a","b","c","d"]')
})
})
\ No newline at end of file
......@@ -4,7 +4,7 @@
<text id="obj-str" class="uni-common-mb">obj.str: {{obj['str']}}</text>
<text id="obj-num" class="uni-common-mb">obj.num: {{obj['num']}}</text>
<text id="obj-arr" class="uni-common-mb">obj.arr: {{obj['arr']}}</text>
<button id="update-btn" @click="update">update</button>
<button class="update-btn" @click="update">update</button>
</view>
</template>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册