basicTest.vue 6.4 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1
<template>
2
    <view class="content">
fxy060608's avatar
fxy060608 已提交
3 4
		<page-head :title="title"></page-head>
        <view v-for="(item,name) in result" :key="name" class="result">
Y
yurj26 已提交
5
            <view>{{name}}测试结果:</view>
fxy060608's avatar
fxy060608 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18
             <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>
fxy060608's avatar
fxy060608 已提交
20 21
    import {
        runTests
22
    } from '../../uni_modules/uts-tests'
F
fxy060608 已提交
23
    import { onTest1, testKeepAlive, testKeepAliveOption, createTest, TestKeepAliveClass } from '@/uni_modules/uts-tests'
F
fxy060608 已提交
24
    import { testNonKeepAlive, testNonKeepAliveOption } from '@/uni_modules/uts-tests'
fxy060608's avatar
fxy060608 已提交
25 26
    export default {
        data() {
27
            return {
F
fxy060608 已提交
28 29 30 31
                title: 'UTS基础语法',
                result: {},
                keepAliveCount: 0,
                nonKeepAliveCount: 0
fxy060608's avatar
fxy060608 已提交
32 33 34 35 36 37
            }
        },
        onReady() {
            this.test()
        },
        methods: {
F
fxy060608 已提交
38
            async test() {
Y
yurj26 已提交
39
                this.result = runTests()
fxy060608's avatar
fxy060608 已提交
40
                console.log(this.result)
F
fxy060608 已提交
41
                console.log('jest_testCallbackKeepAlive:' + await this.jest_testCallbackKeepAlive())
F
fxy060608 已提交
42
                console.log('jest_testCallbackNonKeepAlive:' + await this.jest_testCallbackNonKeepAlive())
43 44 45 46 47 48 49 50 51 52 53 54 55 56
            },
               
            jest_testCallbackKeepAlive() {
              let ret = true
              let count = 0;
              
              onTest1((res) => {
                count++;
                console.log("onTest1 callback =====> ", res)
              })
              
              if (count < 2) {
                ret = false
              }
F
fxy060608 已提交
57
              // count = 0;
58 59 60 61 62 63 64 65 66
              
              testKeepAlive((res) => {
                count++;
                console.log(res)
              })
              
              if (count < 2) {
                ret = false
              }
F
fxy060608 已提交
67
              // count = 0;
68 69 70 71 72 73 74 75 76 77 78 79
              
              testKeepAliveOption({
                a: "testKeepAliveOption",
                success: (res) => {
                  count++;
                  console.log("testKeepAliveOption callback =====> ", res)
                }
              })
              
              if (count < 2) {
                ret = false
              }
F
fxy060608 已提交
80
              // count = 0;
81 82 83 84 85 86 87 88 89
              
              TestKeepAliveClass.onTestStatic((res) => {
                count++;
                console.log("onTestStatic callback =====> ", res)
              })
              
              if (count < 2) {
                ret = false
              }
F
fxy060608 已提交
90
              // count = 0;
91 92 93 94 95 96 97 98 99
              
              TestKeepAliveClass.testKeepAliveStatic((res) => {
                count++;
                console.log("testKeepAliveStatic callback =====> ", res)
              })
              
              if (count < 2) {
                ret = false
              }
F
fxy060608 已提交
100
              // count = 0;
101 102 103 104 105 106 107 108 109 110 111 112
              
              TestKeepAliveClass.testKeepAliveOptionStatic({
                a: "testKeepAliveOption",
                success: (res) => {
                  count++;
                  console.log("testKeepAliveOptionStatic callback =====> ", res)
                }
              })
              
              if (count < 2) {
                ret = false
              }
F
fxy060608 已提交
113
              // count = 0;
114 115 116 117 118 119 120 121 122 123
              
              const obj = new TestKeepAliveClass()
              obj.onTest((res) => {
                count++;
                console.log("TestKeepAliveClass.onTest callback =====> ", res)
              })
              
              if (count < 2) {
                ret = false
              }
F
fxy060608 已提交
124
              // count = 0;
125 126 127 128 129 130 131 132 133
              
              obj.testKeepAlive((res) => {
                count++;
                console.log("TestKeepAliveClass.testKeepAlive callback =====> ", res)
              })
              
              if (count < 2) {
                ret = false
              }
F
fxy060608 已提交
134
              // count = 0;
135 136 137 138 139 140 141 142 143 144 145
              
              obj.testKeepAliveOption({
                a: "testKeepAliveOption",
                success: (res) => {
                  count++;
                  console.log("TestKeepAliveClass.testKeepAliveOption callback =====> ", res)
                }
              })
              if (count < 2) {
                ret = false
              }
F
fxy060608 已提交
146 147 148 149 150 151 152 153 154 155 156
              // count = 0;
              const testImpl = createTest()
              testImpl.test((res) => {
                count++;
                console.log("TestImpl.test callback =====> ", res)
              })
              if (count < 2) {
                ret = false
              }
              return new Promise((resolve)=>{
                setTimeout(()=>{
F
fxy060608 已提交
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
                  this.keepAliveCount = count
                  resolve(count)
                },30)
              })
            },
            jest_testCallbackNonKeepAlive() {
              let ret = true
              let count = 0
              // 使用相同的回调函数多次传递调用,确保每次都正常
              const fn = (res) => {
                count++;
                console.log("testCallbackNonKeepAlive callback =====> ", res)
              }
              testNonKeepAlive(fn)
              testNonKeepAlive(fn)
              if (count < 2) {
                ret = false
              }
              count = 0
              const options = {
                a:'a',
                success(res){
                  count++;
                  console.log("testCallbackNonKeepAliveOption callback =====> ", res)
                }
              }
              testNonKeepAliveOption(options)
              testNonKeepAliveOption(options)
              if (count < 2) {
                ret = false
              }
              return new Promise((resolve)=>{
                setTimeout(()=>{
                  this.nonKeepAliveCount = count
F
fxy060608 已提交
191 192 193
                  resolve(count)
                },30)
              })
fxy060608's avatar
fxy060608 已提交
194 195 196 197
            }
        }
    }
</script>
198 199
<style>
	@import '@/common/uni-uvue.css';
fxy060608's avatar
fxy060608 已提交
200
	
201
    .content {
fxy060608's avatar
fxy060608 已提交
202 203 204 205 206 207 208 209 210 211
		min-height: 100%;
        padding: 32rpx;
    }

    .passed {
        color: green;
    }

    .failed {
        color: red;
Y
yurj26 已提交
212 213 214
    }
    .result {
        margin-bottom: 20rpx;
fxy060608's avatar
fxy060608 已提交
215
    }
Y
yurj26 已提交
216
</style>