tests.uts 763 字节
Newer Older
Y
yurj26 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
import { Matchers } from './Matchers.uts'

export const describes = new Map<string, Result>()

export class Result {
    total = 0
    passed: string[] = []
    failed: string[] = []
}

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) {
        result.failed.push(`${name}:\n${e.message}`)
    }
    result.total++
}

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