提交 f9c4b900 编写于 作者: 杜庆泉's avatar 杜庆泉

storage 增加 类json格式字符串测试示例

上级 7f6591dc
...@@ -217,7 +217,23 @@ describe('ExtApi-StorageInfoTest', () => { ...@@ -217,7 +217,23 @@ describe('ExtApi-StorageInfoTest', () => {
let objRet = await getData('apiGetData') let objRet = await getData('apiGetData')
expect(objRet.name).toEqual("tom") 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"}')
}); });
......
...@@ -78,6 +78,16 @@ ...@@ -78,6 +78,16 @@
> >
填充浮点型 填充浮点型
</button> </button>
</view>
<view class="uni-flex uni-row">
<button
type="default"
style="width:750rpx"
@tap="jsonLikeMock"
>
填充符合json格式的字符串
</button>
</view> </view>
</view> </view>
<view class="uni-padding-wrap"> <view class="uni-padding-wrap">
...@@ -147,6 +157,14 @@ export default { ...@@ -147,6 +157,14 @@ export default {
console.log(e) console.log(e)
} }
}, },
jsonLikeMock(){
this.key = 'key_' + Math.random()
this.data = JSON.stringify({
name: "james",
age: 12,
from:"american"
});
},
strMock() { strMock() {
this.key = 'key_' + Math.random() this.key = 'key_' + Math.random()
this.data = '测试字符串数据,长度为16个字符' this.data = '测试字符串数据,长度为16个字符'
...@@ -197,8 +215,8 @@ export default { ...@@ -197,8 +215,8 @@ export default {
uni.getStorage({ uni.getStorage({
key: key, key: key,
success: (res) => { success: (res) => {
that.apiGetData = res.data
that.apiGetData = res.data
let desc:string = typeof this.apiGetData let desc:string = typeof this.apiGetData
if("object" == desc){ if("object" == desc){
desc = desc + ": " + JSON.stringify(this.apiGetData) desc = desc + ": " + JSON.stringify(this.apiGetData)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册