Extapi.uts 1.7 KB
Newer Older
杜庆泉's avatar
杜庆泉 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
import { describe, test, expect, Result } from './tests.uts'


export function testExtapi() : Result {
	return describe("Storage", () => {
		test('setStorage', () => {

			uni.setStorage({
				key: "dddddd",
				data: 1,
				complete: (res) => {
					let ret = uni.getStorageSync("dddddd")
					expect(ret).toEqual(1)
					uni.setStorageSync("dddddd",3.14159265358)
					ret = uni.getStorageSync("dddddd")
					expect(ret).toEqual(3.14159265358)
				}
			})


			uni.setStorage({
				key: "dddddd",
				data: true,
				complete: (res) => {
					console.log(res)
					let ret = uni.getStorageSync("dddddd")
					expect(ret).toEqual(true)
					uni.setStorageSync("dddddd",false)
					ret = uni.getStorageSync("dddddd")
					expect(ret).toEqual(false)
				}
			})
			
			
			uni.setStorage({
				key: "dddddd",
				data: "海上生明月,天涯共此时,情人怨遥夜,竟夕起相思。",
				complete: (res) => {
					console.log(res)
					let ret = uni.getStorageSync("dddddd")
					expect(ret).toEqual("海上生明月,天涯共此时,情人怨遥夜,竟夕起相思。")
					uni.setStorageSync("dddddd","床前明月光,疑似地上霜")
					ret = uni.getStorageSync("dddddd")
					expect(ret).toEqual("床前明月光,疑似地上霜")
				}
			})
			
			
			// IOS 打印对象乱序,暂时注释
			// uni.setStorage({
			// 	key: "dddddd",
			// 	data: {
			// 		"a": 1,
			// 		"b": "2",
			// 		"c": {
			// 			"x": "1",
			// 			"y": true
			// 		}
			// 	},
			// 	complete: (res) => {
			// 		let ret = uni.getStorageSync("dddddd")
			// 		console.log(ret)
			// 		expect(JSON.stringify(ret)).toEqual('{"a":1,"b":"2","c":{"x":"1","y":true}}')
			// 	}
			// })
		})


	})
}