From f9c4b90061eb12700a768435f0dddcab6208a9fb Mon Sep 17 00:00:00 2001 From: duqingquan Date: Fri, 19 Jan 2024 10:53:58 +0800 Subject: [PATCH] =?UTF-8?q?storage=20=E5=A2=9E=E5=8A=A0=20=E7=B1=BBjson?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/API/storage/storage.test.js | 26 +++++++++++++++++++++----- pages/API/storage/storage.uvue | 20 +++++++++++++++++++- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/pages/API/storage/storage.test.js b/pages/API/storage/storage.test.js index d50ec89d..312e09c7 100644 --- a/pages/API/storage/storage.test.js +++ b/pages/API/storage/storage.test.js @@ -168,18 +168,18 @@ describe('ExtApi-StorageInfoTest', () => { await btnGetStorageButtonInfo.tap() await page.waitFor(600) expect(await getData('apiGetData')).toEqual(12345789.235689) - - + + // 测试 remove await btnGetStorageInfoSyncButton.tap() await page.waitFor(600) storageInfoRet = await getData('apiGetData') expect(storageInfoRet.keys[0]).toEqual("autotest_key_mock") - + const btnRemoveStorageInfoSyncButton = await page.$('.btn-removeStorageInfoSync') await btnRemoveStorageInfoSyncButton.tap() page.waitFor(600) - + await btnGetStorageInfoSyncButton.tap() await page.waitFor(600) storageInfoRet = await getData('apiGetData') @@ -217,7 +217,23 @@ describe('ExtApi-StorageInfoTest', () => { let objRet = await getData('apiGetData') expect(objRet.name).toEqual("tom") - + await page.setData({ + key: "autotest_key_mock", + data:JSON.stringify({ + name: "james", + age: 12, + from:"american" + }) + }) + await page.waitFor(600) + btnSetStorageButtonInfo = await page.$('.btn-setstorageSync') + await btnSetStorageButtonInfo.tap() + await page.waitFor(600) + btnGetStorageButtonInfo = await page.$('.btn-getstorageSync') + await btnGetStorageButtonInfo.tap() + await page.waitFor(600) + let jsonStr = await getData('apiGetData') + expect(jsonStr).toEqual('{"age":12,"from":"american","name":"james"}') }); diff --git a/pages/API/storage/storage.uvue b/pages/API/storage/storage.uvue index 330d869a..fb41f478 100644 --- a/pages/API/storage/storage.uvue +++ b/pages/API/storage/storage.uvue @@ -78,6 +78,16 @@ > 填充浮点型 + + + + @@ -147,6 +157,14 @@ export default { console.log(e) } }, + jsonLikeMock(){ + this.key = 'key_' + Math.random() + this.data = JSON.stringify({ + name: "james", + age: 12, + from:"american" + }); + }, strMock() { this.key = 'key_' + Math.random() this.data = '测试字符串数据,长度为16个字符' @@ -197,8 +215,8 @@ export default { uni.getStorage({ key: key, success: (res) => { - that.apiGetData = res.data + that.apiGetData = res.data let desc:string = typeof this.apiGetData if("object" == desc){ desc = desc + ": " + JSON.stringify(this.apiGetData) -- GitLab