From 6bf6115b8417e45e6e4c67672360c9367596c6cc Mon Sep 17 00:00:00 2001 From: fxy060608 <153647646@qq.com> Date: Thu, 12 Sep 2024 14:00:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4uts=E6=8F=92=E4=BB=B6keepAliv?= =?UTF-8?q?e=E6=B5=8B=E8=AF=95=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/basicTest.test.js | 8 +++----- pages/index/basicTest.vue | 26 ++++++++++++++++++-------- uni_modules/uts-tests/utssdk/index.uts | 17 +++++++++++++++++ 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/pages/index/basicTest.test.js b/pages/index/basicTest.test.js index 0db3c67..1bd8b7a 100644 --- a/pages/index/basicTest.test.js +++ b/pages/index/basicTest.test.js @@ -46,7 +46,7 @@ if (process.env.UNI_PROJECT_TYPE === '2.0' && process.env.uniTestPlatformInfo.to } if (process.env.UNI_PROJECT_TYPE === '2.0' && (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios') || process.env.uniTestPlatformInfo.startsWith('android'))) { - describe('testCallbackKeepAlive', () => { + describe('testCallbackKeepAlive2.0', () => { it("jest_testCallbackKeepAlive", async () => { const res = await page.callMethod('jest_testCallbackKeepAlive') expect(res).toEqual(true) @@ -55,12 +55,10 @@ if (process.env.UNI_PROJECT_TYPE === '2.0' && (process.env.uniTestPlatformInfo.t } if (process.env.UNI_PROJECT_TYPE === '1.0' && (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios') || process.env.uniTestPlatformInfo.startsWith('android'))) { - describe('testCallbackKeepAlive', () => { + describe('testCallbackKeepAlive1.0', () => { it("jest_testCallbackKeepAlive", async () => { const res = await page.callMethod('jest_testCallbackKeepAlive') - page.waitFor(100) - const count = await page.data('count') - expect(count).toEqual(18) + expect(res).toEqual(20) }) }) } diff --git a/pages/index/basicTest.vue b/pages/index/basicTest.vue index eac79a1..1da1f20 100644 --- a/pages/index/basicTest.vue +++ b/pages/index/basicTest.vue @@ -20,22 +20,22 @@ import { runTests } from '../../uni_modules/uts-tests' - import { onTest1, testKeepAlive, testKeepAliveOption, TestKeepAliveClass } from '@/uni_modules/uts-tests' + import { onTest1, testKeepAlive, testKeepAliveOption, createTest, TestKeepAliveClass } from '@/uni_modules/uts-tests' export default { data() { return { title: 'UTS基础语法', - result: {}, - count: 0 + result: {} } }, onReady() { this.test() }, methods: { - test() { + async test() { this.result = runTests() console.log(this.result) + console.log('jest_testCallbackKeepAlive:' + await this.jest_testCallbackKeepAlive()) }, jest_testCallbackKeepAlive() { @@ -139,10 +139,20 @@ if (count < 2) { ret = false } - setTimeout(()=>{ - this.count = count - },50) - return ret + // count = 0; + const testImpl = createTest() + testImpl.test((res) => { + count++; + console.log("TestImpl.test callback =====> ", res) + }) + if (count < 2) { + ret = false + } + return new Promise((resolve)=>{ + setTimeout(()=>{ + resolve(count) + },30) + }) } } } diff --git a/uni_modules/uts-tests/utssdk/index.uts b/uni_modules/uts-tests/utssdk/index.uts index cfe8611..3a2ed7b 100644 --- a/uni_modules/uts-tests/utssdk/index.uts +++ b/uni_modules/uts-tests/utssdk/index.uts @@ -141,5 +141,22 @@ export class TestKeepAliveClass { option.success?.("2") } } + + +interface ITest { + test(callback : (msg : string) => void) : void +} + +class TestImpl implements ITest { + @UTSJS.keepAlive + test(callback : (msg : string) => void) : void { + callback("1") + callback("2") + } +} + +export function createTest() : ITest { + return new TestImpl() +} // #endif -- GitLab