console.uts 1.3 KB
Newer Older
杜庆泉's avatar
杜庆泉 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
import { describe, test, expect, expectNumber, Result } from './tests.uts'

function obtainInnerObject(obj:Any | null):UTSJSONObject{
  let jsonStr = console.getLogV2(obj).slice(19,-17)
  let a = JSON.parseArray(jsonStr)![0]
  return a as UTSJSONObject
}

export function testConsole() : Result {
  return describe("log", () => {
    test('log-native-obj', () => {
      // #ifdef APP-ANDROID
        expect(obtainInnerObject(0.9).get("type")).toEqual("Double");
        expect(obtainInnerObject(0.9).get("subType")).toEqual("number");
        expect(obtainInnerObject(0.9).get("value")).toEqual("0.9");
杜庆泉's avatar
杜庆泉 已提交
16 17 18 19 20 21 22
        
      // #endif
      
      // #ifdef UNI-APP-X && APP-ANDROID
        let pageInstance = new io.dcloud.uniapp.vue.ComponentInternalInstance()
        expect(obtainInnerObject(pageInstance).get("className")).toEqual("io.dcloud.uniapp.vue.ComponentInternalInstance");
        expect(obtainInnerObject(pageInstance).get("type")).toEqual("object");
杜庆泉's avatar
杜庆泉 已提交
23
      // #endif
杜庆泉's avatar
杜庆泉 已提交
24 25 26 27 28 29 30
    })
    
    test('console-number-from-JSON-parse', () => {
      // #ifdef APP-ANDROID
      
      let aj2 = JSON.parse('{"a":1}') as UTSJSONObject;
      
杜庆泉's avatar
杜庆泉 已提交
31 32
      expect(obtainInnerObject(aj2['a']).get("type")).toEqual("number");
      expect(obtainInnerObject(aj2['a']).get("subType")).toEqual("number");
杜庆泉's avatar
杜庆泉 已提交
33 34 35 36 37
      
      // #endif
      
    })
    
杜庆泉's avatar
杜庆泉 已提交
38
  })
杜庆泉's avatar
杜庆泉 已提交
39
  
杜庆泉's avatar
杜庆泉 已提交
40
}