tests.uts 892 字节
Newer Older
1
import { Matchers,NumberMatchers } from './Matchers.uts'
Y
yurj26 已提交
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

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) {
27
        result.failed.push(`${name}:\n${(e as Error).message}`)
Y
yurj26 已提交
28 29 30 31 32 33 34
    }
    result.total++
}

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

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