basicTest.uvue 3.0 KB
Newer Older
Y
yurj26 已提交
1
<template>
DCloud-WZF's avatar
DCloud-WZF 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14
  <!-- #ifdef APP -->
  <scroll-view style="flex: 1">
    <!-- #endif -->
    <view class="content">
      <page-head :title="title"></page-head>
      <view v-for="(item, index) in resultArray" :key="index" class="result">
        <view>{{ names[index] }}测试结果:</view>
        <view> 测试api:{{ item.passed.join(', ') }} </view>
        <view>总共:{{ item.total }}</view>
        <view>通过:{{ item.passed.length }}</view>
        <view>失败:{{ item.failed.length }}</view>
        <view v-for="(fail, i) in item.failed" :key="i">
          <text class="failed">{{ fail }}</text>
Y
yurj26 已提交
15
        </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
16
      </view>
Y
yurj26 已提交
17
    </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
18 19 20
    <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
Y
yurj26 已提交
21
</template>
22
<script lang="ts">
23 24
import { runTests, Result } from '../../uni_modules/uts-tests'
// #ifdef APP-IOS
lizhongyi_'s avatar
lizhongyi_ 已提交
25 26
import { testTypeFromAppJs, Options } from '@/uni_modules/uts-ios-tests';
import { onTest1, testKeepAlive, testKeepAliveOption, TestKeepAliveClass } from '@/uni_modules/uts-tests'
27
// #endif
DCloud-WZF's avatar
DCloud-WZF 已提交
28 29 30 31 32 33 34
export default {
  data() {
    return {
      title: 'UTS基础语法',
      resultArray: [] as Result[],
      result: {} as UTSJSONObject,
      names: [] as string[],
Y
yurj26 已提交
35
    }
DCloud-WZF's avatar
DCloud-WZF 已提交
36 37 38 39 40 41
  },
  onReady() {
    this.test()
  },
  methods: {
    test() {
lizhongyi_'s avatar
lizhongyi_ 已提交
42 43 44 45 46 47 48 49 50 51 52
      this.result = runTests()
      // const resultMap = this.result.toMap()
      // resultMap.forEach((res, name) => {
      //   this.names.push(name)
      //   this.resultArray.push(res as Result)
      // })
      const resultMap = this.result
      for (const key in resultMap) {
        this.names.push(key)
        this.resultArray.push(resultMap[key] as Result)
      }
53 54 55 56 57 58
    },
    // #ifdef APP-IOS
    jest_testTypeFromAppJs() {
      return testTypeFromAppJs({
        num: 1
      } as Options)
lizhongyi_'s avatar
lizhongyi_ 已提交
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
    },
    // #endif
    // #ifdef APP-IOS
    jest_testCallbackKeepAlive() {
      
      onTest1((res) => {
        console.log(res)
      })
      
      testKeepAlive((res) => {
        console.log(res)
      })
      
      testKeepAliveOption({
        a: "testKeepAliveOption",
        success: (res) => {
          console.log(res)
        }
      })
      
      TestKeepAliveClass.onTestStatic((res) => {
        console.log(res)
      })
      
      TestKeepAliveClass.testKeepAliveStatic((res) => {
        console.log(res)
      })
      
      TestKeepAliveClass.testKeepAliveOptionStatic({
        a: "testKeepAliveOption",
        success: (res) => {
          console.log(res)
        }
      })
      
      const obj = new TestKeepAliveClass()
      obj.onTest((res) => {
        console.log(res)
      })
      
      obj.testKeepAlive((res) => {
        console.log(res)
      })
      
      obj.testKeepAliveOption({
        a: "testKeepAliveOption",
        success: (res) => {
          console.log(res)
        }
      })
      
      return true
111 112
    }
    // #endif
DCloud-WZF's avatar
DCloud-WZF 已提交
113 114
  },
}
Y
yurj26 已提交
115
</script>
DCloud-WZF's avatar
DCloud-WZF 已提交
116 117 118 119 120
<style>
@import '@/common/uni-uvue.css';
.content {
  padding: 32rpx;
}
Y
yurj26 已提交
121

DCloud-WZF's avatar
DCloud-WZF 已提交
122 123 124
.passed {
  color: green;
}
Y
yurj26 已提交
125

DCloud-WZF's avatar
DCloud-WZF 已提交
126 127 128
.failed {
  color: red;
}
Y
yurj26 已提交
129

DCloud-WZF's avatar
DCloud-WZF 已提交
130 131 132 133
.result {
  margin-bottom: 20rpx;
}
</style>