Matchers.uts 642 字节
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

export class Matchers<T> {
    private actual: T
    constructor(actual: T) {
        this.actual = actual
    }
    toEqual(expected: T) {
        if (JSON.stringify(expected) == JSON.stringify(this.actual)) {
            return
        }
        // #ifndef APP-IOS
        throw new Error(format(expected, this.actual))
        // #endif
        // #ifdef APP-IOS
        NSException(name = NSExceptionName.internalInconsistencyException, reason = format(expected, this.actual)).raise()
        // #endif
    }
}

function format(expected: any | null, actual: any | null): string {
    return `expected:<${expected}> but was:<${actual}>`
}