basicTest.vue 4.6 KB
Newer Older
Y
yurj26 已提交
1
<template>
2 3
    <view class="content">
		<page-head :title="title"></page-head>
Y
yurj26 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
        <view v-for="(item,name) in result" :key="name" class="result">
            <view>{{name}}测试结果:</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,index) in item.failed" :key="index" class="failed">
                <view>{{fail.split('\n')[0]}}</view>
                <view>{{fail.split('\n')[1]}}</view>
            </view>
        </view>
    </view>
</template>
19
<script>
Y
yurj26 已提交
20 21
    import {
        runTests
22
    } from '../../uni_modules/uts-tests'
23
    import { onTest1, testKeepAlive, testKeepAliveOption, TestKeepAliveClass } from '@/uni_modules/uts-tests'
Y
yurj26 已提交
24 25
    export default {
        data() {
26 27
            return {
				title: 'UTS基础语法',
F
fxy060608 已提交
28 29
                result: {},
                count: 0
Y
yurj26 已提交
30 31 32 33 34 35 36 37 38
            }
        },
        onReady() {
            this.test()
        },
        methods: {
            test() {
                this.result = runTests()
                console.log(this.result)
39 40 41 42 43 44 45 46 47 48 49 50 51 52
            },
               
            jest_testCallbackKeepAlive() {
              let ret = true
              let count = 0;
              
              onTest1((res) => {
                count++;
                console.log("onTest1 callback =====> ", res)
              })
              
              if (count < 2) {
                ret = false
              }
F
fxy060608 已提交
53
              // count = 0;
54 55 56 57 58 59 60 61 62
              
              testKeepAlive((res) => {
                count++;
                console.log(res)
              })
              
              if (count < 2) {
                ret = false
              }
F
fxy060608 已提交
63
              // count = 0;
64 65 66 67 68 69 70 71 72 73 74 75
              
              testKeepAliveOption({
                a: "testKeepAliveOption",
                success: (res) => {
                  count++;
                  console.log("testKeepAliveOption callback =====> ", res)
                }
              })
              
              if (count < 2) {
                ret = false
              }
F
fxy060608 已提交
76
              // count = 0;
77 78 79 80 81 82 83 84 85
              
              TestKeepAliveClass.onTestStatic((res) => {
                count++;
                console.log("onTestStatic callback =====> ", res)
              })
              
              if (count < 2) {
                ret = false
              }
F
fxy060608 已提交
86
              // count = 0;
87 88 89 90 91 92 93 94 95
              
              TestKeepAliveClass.testKeepAliveStatic((res) => {
                count++;
                console.log("testKeepAliveStatic callback =====> ", res)
              })
              
              if (count < 2) {
                ret = false
              }
F
fxy060608 已提交
96
              // count = 0;
97 98 99 100 101 102 103 104 105 106 107 108
              
              TestKeepAliveClass.testKeepAliveOptionStatic({
                a: "testKeepAliveOption",
                success: (res) => {
                  count++;
                  console.log("testKeepAliveOptionStatic callback =====> ", res)
                }
              })
              
              if (count < 2) {
                ret = false
              }
F
fxy060608 已提交
109
              // count = 0;
110 111 112 113 114 115 116 117 118 119
              
              const obj = new TestKeepAliveClass()
              obj.onTest((res) => {
                count++;
                console.log("TestKeepAliveClass.onTest callback =====> ", res)
              })
              
              if (count < 2) {
                ret = false
              }
F
fxy060608 已提交
120
              // count = 0;
121 122 123 124 125 126 127 128 129
              
              obj.testKeepAlive((res) => {
                count++;
                console.log("TestKeepAliveClass.testKeepAlive callback =====> ", res)
              })
              
              if (count < 2) {
                ret = false
              }
F
fxy060608 已提交
130
              // count = 0;
131 132 133 134 135 136 137 138 139 140 141
              
              obj.testKeepAliveOption({
                a: "testKeepAliveOption",
                success: (res) => {
                  count++;
                  console.log("TestKeepAliveClass.testKeepAliveOption callback =====> ", res)
                }
              })
              if (count < 2) {
                ret = false
              }
F
fxy060608 已提交
142 143 144
              setTimeout(()=>{
                this.count = count
              },10)
145
              return ret
Y
yurj26 已提交
146 147 148 149
            }
        }
    }
</script>
150 151 152 153 154
<style>
	@import '@/common/uni-uvue.css';
	
    .content {
		min-height: 100%;
Y
yurj26 已提交
155 156 157 158 159 160 161 162 163 164 165 166 167 168
        padding: 32rpx;
    }

    .passed {
        color: green;
    }

    .failed {
        color: red;
    }
    .result {
        margin-bottom: 20rpx;
    }
</style>