import { assert } from "chai" ; import { SuiteFunction , PendingSuiteFunction , TestFunction , PendingTestFunction } from "mocha" ; import { isNode } from "../lib/util/utils" ; export const nodeIt = ! isNode ? it . skip : it ; export const browserIt = isNode ? it . skip : it ; export const nodeDescribe = ! isNode ? describe . skip : describe ; export const browserDescribe = isNode ? describe . skip : describe ; param syncFunction param expectedError export function throws ( syncFunction , expectedError ? ) { let thrownError ; try { syncFunction ( ) ; } catch ( error ) { thrownError = error ; } if ( ! thrownError ) { assert . throws ( ( ) => { } ) ; } else if ( expectedError instanceof Error ) { assert . deepEqual ( thrownError , expectedError ) ; } else if ( expectedError ) { expectedError ( thrownError ) ; } return thrownError ! ; } param asyncFunction param expectedError export async function throwsAsync < T > ( asyncFunction , expectedError ? ) { let thrownError ; try { await ( typeof asyncFunction === "function" ? asyncFunction ( ) : asyncFunction ) ; } catch ( error ) { thrownError = error ; } if ( ! thrownError ) { assert . throws ( ( ) => { } ) ; } else if ( expectedError instanceof Error ) { assert . deepEqual ( thrownError , expectedError ) ; } else if ( expectedError ) { expectedError ( thrownError ) ; } return thrownError ! ; }