From 3a44facab77d75fabaae7143f136e1578cb6aacd Mon Sep 17 00:00:00 2001 From: zhenyuWang <13641039885@163.com> Date: Tue, 23 Jan 2024 22:11:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=B0=83=E6=95=B4=E7=A4=BA=E4=BE=8B?= =?UTF-8?q?=E5=8F=8A=E6=B5=8B=E8=AF=95=EF=BC=8C=E5=85=BC=E5=AE=B9=20web=20?= =?UTF-8?q?=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../basic/define-expose/define-expose.test.js | 2 +- .../basic/define-expose/define-expose.uvue | 2 +- pages/composition-api/basic/use-slots/Foo.uvue | 2 +- .../basic/use-slots/use-slots.test.js | 4 ++-- .../dependency-injection/provide/inject.uvue | 11 +++++++---- .../provide/provide-inject.test.js | 14 ++++++++------ .../reactivity/custom-ref/custom-ref.test.js | 13 ++++++++----- .../reactivity/custom-ref/custom-ref.uvue | 4 ++-- .../reactivity/reactive/reactive.test.js | 6 +++--- .../reactivity/reactive/reactive.uvue | 2 +- 10 files changed, 34 insertions(+), 26 deletions(-) diff --git a/pages/composition-api/basic/define-expose/define-expose.test.js b/pages/composition-api/basic/define-expose/define-expose.test.js index e4ea03d..5ab000e 100644 --- a/pages/composition-api/basic/define-expose/define-expose.test.js +++ b/pages/composition-api/basic/define-expose/define-expose.test.js @@ -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') diff --git a/pages/composition-api/basic/define-expose/define-expose.uvue b/pages/composition-api/basic/define-expose/define-expose.uvue index d5de479..c5d20b7 100644 --- a/pages/composition-api/basic/define-expose/define-expose.uvue +++ b/pages/composition-api/basic/define-expose/define-expose.uvue @@ -3,7 +3,7 @@ str from component Foo: {{fooStr}} num from component Foo: {{fooNum}} - + diff --git a/pages/composition-api/basic/use-slots/Foo.uvue b/pages/composition-api/basic/use-slots/Foo.uvue index bea3cb5..a58efe7 100644 --- a/pages/composition-api/basic/use-slots/Foo.uvue +++ b/pages/composition-api/basic/use-slots/Foo.uvue @@ -4,7 +4,7 @@ check useSlots result: {{ checkUseSlotsRes }} - diff --git a/pages/composition-api/basic/use-slots/use-slots.test.js b/pages/composition-api/basic/use-slots/use-slots.test.js index 796c84b..ab45886 100644 --- a/pages/composition-api/basic/use-slots/use-slots.test.js +++ b/pages/composition-api/basic/use-slots/use-slots.test.js @@ -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') diff --git a/pages/composition-api/dependency-injection/provide/inject.uvue b/pages/composition-api/dependency-injection/provide/inject.uvue index 3b52b5f..58f09a8 100644 --- a/pages/composition-api/dependency-injection/provide/inject.uvue +++ b/pages/composition-api/dependency-injection/provide/inject.uvue @@ -7,7 +7,7 @@ arr: {{arr}} fn: {{(fn as () => string)()}} hasInjectionContext: - {{checkHasInjectionContextRes}} + {{checkHasInjectionContextRes}} @@ -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() \ No newline at end of file diff --git a/pages/composition-api/dependency-injection/provide/provide-inject.test.js b/pages/composition-api/dependency-injection/provide/provide-inject.test.js index 7ec742e..6e71429 100644 --- a/pages/composition-api/dependency-injection/provide/provide-inject.test.js +++ b/pages/composition-api/dependency-injection/provide/provide-inject.test.js @@ -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 diff --git a/pages/composition-api/reactivity/custom-ref/custom-ref.test.js b/pages/composition-api/reactivity/custom-ref/custom-ref.test.js index 9f41840..4fb8ecf 100644 --- a/pages/composition-api/reactivity/custom-ref/custom-ref.test.js +++ b/pages/composition-api/reactivity/custom-ref/custom-ref.test.js @@ -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 diff --git a/pages/composition-api/reactivity/custom-ref/custom-ref.uvue b/pages/composition-api/reactivity/custom-ref/custom-ref.uvue index d0e3292..2af6b8c 100644 --- a/pages/composition-api/reactivity/custom-ref/custom-ref.uvue +++ b/pages/composition-api/reactivity/custom-ref/custom-ref.uvue @@ -1,8 +1,8 @@ diff --git a/pages/composition-api/reactivity/reactive/reactive.test.js b/pages/composition-api/reactivity/reactive/reactive.test.js index 20c4af4..ad69625 100644 --- a/pages/composition-api/reactivity/reactive/reactive.test.js +++ b/pages/composition-api/reactivity/reactive/reactive.test.js @@ -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 diff --git a/pages/composition-api/reactivity/reactive/reactive.uvue b/pages/composition-api/reactivity/reactive/reactive.uvue index a71c5dc..7c06167 100644 --- a/pages/composition-api/reactivity/reactive/reactive.uvue +++ b/pages/composition-api/reactivity/reactive/reactive.uvue @@ -4,7 +4,7 @@ obj.str: {{obj['str']}} obj.num: {{obj['num']}} obj.arr: {{obj['arr']}} - + -- GitLab