basicTest.vue 4.6 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'
23
    import { onTest1, testKeepAlive, testKeepAliveOption, TestKeepAliveClass } from '@/uni_modules/uts-tests'
fxy060608's avatar
fxy060608 已提交
24 25
    export default {
        data() {
26
            return {
fxy060608's avatar
fxy060608 已提交
27
				title: 'UTS基础语法',
F
fxy060608 已提交
28
                result: {},
fxy060608's avatar
fxy060608 已提交
29 30 31 32 33 34 35 36
                count: 0
            }
        },
        onReady() {
            this.test()
        },
        methods: {
            test() {
Y
yurj26 已提交
37
                this.result = runTests()
fxy060608's avatar
fxy060608 已提交
38
                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
              setTimeout(()=>{
                this.count = count
fxy060608's avatar
fxy060608 已提交
144
              },50)
145
              return ret
fxy060608's avatar
fxy060608 已提交
146 147 148 149
            }
        }
    }
</script>
150 151
<style>
	@import '@/common/uni-uvue.css';
fxy060608's avatar
fxy060608 已提交
152
	
153
    .content {
fxy060608's avatar
fxy060608 已提交
154 155 156 157 158 159 160 161 162 163
		min-height: 100%;
        padding: 32rpx;
    }

    .passed {
        color: green;
    }

    .failed {
        color: red;
Y
yurj26 已提交
164 165 166
    }
    .result {
        margin-bottom: 20rpx;
fxy060608's avatar
fxy060608 已提交
167
    }
Y
yurj26 已提交
168
</style>