basicTest.vue 4.5 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基础语法',
Y
yurj26 已提交
28 29 30 31 32 33 34 35 36 37
                result: {}
            }
        },
        onReady() {
            this.test()
        },
        methods: {
            test() {
                this.result = runTests()
                console.log(this.result)
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
            },
               
            jest_testCallbackKeepAlive() {
              let ret = true
              let count = 0;
              
              onTest1((res) => {
                count++;
                console.log("onTest1 callback =====> ", res)
              })
              
              if (count < 2) {
                ret = false
              }
              count = 0;
              
              testKeepAlive((res) => {
                count++;
                console.log(res)
              })
              
              if (count < 2) {
                ret = false
              }
              count = 0;
              
              testKeepAliveOption({
                a: "testKeepAliveOption",
                success: (res) => {
                  count++;
                  console.log("testKeepAliveOption callback =====> ", res)
                }
              })
              
              if (count < 2) {
                ret = false
              }
              count = 0;
              
              TestKeepAliveClass.onTestStatic((res) => {
                count++;
                console.log("onTestStatic callback =====> ", res)
              })
              
              if (count < 2) {
                ret = false
              }
              count = 0;
              
              TestKeepAliveClass.testKeepAliveStatic((res) => {
                count++;
                console.log("testKeepAliveStatic callback =====> ", res)
              })
              
              if (count < 2) {
                ret = false
              }
              count = 0;
              
              TestKeepAliveClass.testKeepAliveOptionStatic({
                a: "testKeepAliveOption",
                success: (res) => {
                  count++;
                  console.log("testKeepAliveOptionStatic callback =====> ", res)
                }
              })
              
              if (count < 2) {
                ret = false
              }
              count = 0;
              
              const obj = new TestKeepAliveClass()
              obj.onTest((res) => {
                count++;
                console.log("TestKeepAliveClass.onTest callback =====> ", res)
              })
              
              if (count < 2) {
                ret = false
              }
              count = 0;
              
              obj.testKeepAlive((res) => {
                count++;
                console.log("TestKeepAliveClass.testKeepAlive callback =====> ", res)
              })
              
              if (count < 2) {
                ret = false
              }
              count = 0;
              
              obj.testKeepAliveOption({
                a: "testKeepAliveOption",
                success: (res) => {
                  count++;
                  console.log("TestKeepAliveClass.testKeepAliveOption callback =====> ", res)
                }
              })
              if (count < 2) {
                ret = false
              }
              return ret
Y
yurj26 已提交
142 143 144 145
            }
        }
    }
</script>
146 147 148 149 150
<style>
	@import '@/common/uni-uvue.css';
	
    .content {
		min-height: 100%;
Y
yurj26 已提交
151 152 153 154 155 156 157 158 159 160 161 162 163 164
        padding: 32rpx;
    }

    .passed {
        color: green;
    }

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