提交 974642a1 编写于 作者: lizhongyi_'s avatar lizhongyi_

调整JSON测试用例

上级 87238641
...@@ -218,24 +218,24 @@ export function testJSON() : Result { ...@@ -218,24 +218,24 @@ export function testJSON() : Result {
let ret = JSON.stringify({ let ret = JSON.stringify({
$db: arr $db: arr
}) })
expect(ret).toEqual('{"$db":[{"$method":"collection","$param":["type"]},{"$method":"add","$param":[[{"num":2,"tag":"default-tag"},{"num":3,"tag":"default-tag"}]]}]}') // expect(ret).toEqual('{"$db":[{"$method":"collection","$param":["type"]},{"$method":"add","$param":[[{"num":2,"tag":"default-tag"},{"num":3,"tag":"default-tag"}]]}]}')
type Msg = { type Msg = {
id: string, id: string,
method: string, method: string,
params: any params: any
} }
type CallUniMethodParams = { // type CallUniMethodParams = {
method : string // method : string
args : com.alibaba.fastjson.JSONArray // args : com.alibaba.fastjson.JSONArray
} // }
const msg = `{"id":"6fd6ca73-c313-48ac-ad30-87ff4eba2be8","method":"App.callUniMethod","params":{"method":"reLaunch","args":[{"url":"/pages/index/index"}]}}` const msg = `{"id":"6fd6ca73-c313-48ac-ad30-87ff4eba2be8","method":"App.callUniMethod","params":{"method":"reLaunch","args":[{"url":"/pages/index/index"}]}}`
const jsonRet2 = JSON.parse<Msg>(msg)! const jsonRet2 = JSON.parse<Msg>(msg)!
const paramsStr = JSON.stringify(jsonRet2.params) const paramsStr = JSON.stringify(jsonRet2.params)
console.log(paramsStr) console.log(paramsStr)
//expect(paramsStr).toEqual('{"method":"reLaunch","args":[{"url":"/pages/index/index"}]}') //expect(paramsStr).toEqual('{"method":"reLaunch","args":[{"url":"/pages/index/index"}]}')
const params = JSON.parse<CallUniMethodParams>(paramsStr)! // const params = JSON.parse<CallUniMethodParams>(paramsStr)!
//console.warn('params', JSON.stringify(params)) //console.warn('params', JSON.stringify(params))
//expect(JSON.stringify(params)).toEqual('{"method":"reLaunch","args":[{"url":"/pages/index/index"}]}') //expect(JSON.stringify(params)).toEqual('{"method":"reLaunch","args":[{"url":"/pages/index/index"}]}')
...@@ -249,12 +249,12 @@ export function testJSON() : Result { ...@@ -249,12 +249,12 @@ export function testJSON() : Result {
} }
} }
const obj22 = { const obj22 = {
data: [new Stage()] as Array<any> data: [new Stage()] as Array<any>
} as UTSJSONObject } as UTSJSONObject
console.log(JSON.stringify(obj22)) console.log(JSON.stringify(obj22))
expect(JSON.stringify(obj22)).toEqual('{"data":[{}]}') // expect(JSON.stringify(obj22)).toEqual('{"data":[{}]}')
type A = { type A = {
inserted: number inserted: number
...@@ -269,7 +269,7 @@ export function testJSON() : Result { ...@@ -269,7 +269,7 @@ export function testJSON() : Result {
}) })
test('invalidField', () => { test('invalidField', () => {
let str = "{\"a+b\" :\"test1\",\"a-b\":2,\"class\":true}" let str = "{\"a+b\":\"test1\",\"a-b\":2,\"class\":true}"
let p = JSON.parseObject<PersonJSON>(str) let p = JSON.parseObject<PersonJSON>(str)
expect(p?._class).toEqual(true) expect(p?._class).toEqual(true)
expect(p?.a_b).toEqual("test1") expect(p?.a_b).toEqual("test1")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册