tests.uts 1.2 KB
Newer Older
1
import { Matchers,NumberMatchers } from './Matchers.uts'
Y
yurj26 已提交
2 3

export const describes = new Map<string, Result>()
4
// #ifndef APP-IOS
杜庆泉's avatar
杜庆泉 已提交
5
export class Result implements IJSONStringify {
Y
yurj26 已提交
6 7 8
    total = 0
    passed: string[] = []
    failed: string[] = []
杜庆泉's avatar
杜庆泉 已提交
9
	
10 11 12
    toJSON():any|null{
      let jsonRet = {
        'total': this.total,
13 14
          'passed': this.passed,
          'failed': this.failed,
15 16 17 18 19 20 21 22 23 24 25
      }
      return jsonRet
    }
}
// #endif

// #ifdef APP-IOS
export class Result {
    total = 0
    passed: string[] = []
    failed: string[] = []
Y
yurj26 已提交
26
}
27 28
// #endif

Y
yurj26 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

let result: Result = new Result()

export function describe(name: string, fn: () => void): Result {
    result = new Result()
    describes.set(name, result)
    fn()
    return result
}

export function test(name: string, fn: () => void) {
    try {
        fn()
        // console.log('push....',name)
        result.passed.push(name)
        // console.log('push....',result.passed.length)
    } catch (e) {
46
        result.failed.push(`${name}:\n${e.message}`)
Y
yurj26 已提交
47 48 49 50 51 52 53
    }
    result.total++
}

export function expect<T>(value: T): Matchers<T> {
    return new Matchers(value);
}
54 55 56 57

export function expectNumber(value: number): NumberMatchers {
    return new NumberMatchers(value);
}