4b06f42db7
* sort of works * type fixes * added option to run old way too
56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
import type { MaybeAsync } from '@speckle/shared'
|
|
import { ensureError } from '@speckle/shared'
|
|
import { AssertionError } from 'chai'
|
|
|
|
export const expectToThrow = async (fn: () => MaybeAsync<any>) => {
|
|
try {
|
|
await fn()
|
|
} catch (err) {
|
|
return ensureError(err)
|
|
}
|
|
|
|
throw new AssertionError("Function was expected to throw, but didn't")
|
|
}
|
|
|
|
/**
|
|
* Create parameterizable test cases for each element in an array
|
|
*/
|
|
export const itEach = <T>(
|
|
testCases: Array<T> | ReadonlyArray<T>,
|
|
name: (test: T) => string,
|
|
testHandler: (test: T) => MaybeAsync<void>,
|
|
options?: Partial<{
|
|
/**
|
|
* Mark tests as skipped
|
|
*/
|
|
skip: boolean
|
|
}>
|
|
) => {
|
|
testCases.forEach((testCase) => {
|
|
const itFn = options?.skip ? it.skip : it
|
|
itFn(name(testCase), testHandler.bind(null, testCase))
|
|
})
|
|
}
|
|
|
|
/**
|
|
* Create pararmeterizable describe blocks for each element in an array
|
|
*/
|
|
export const describeEach = <T>(
|
|
describeCases: Array<T> | ReadonlyArray<T>,
|
|
name: (describe: T) => string,
|
|
describeHandler: (describe: T) => void,
|
|
options?: Partial<{
|
|
/**
|
|
* Mark tests as skipped
|
|
*
|
|
*/
|
|
skip: boolean
|
|
}>
|
|
) => {
|
|
describeCases.forEach((testCase) => {
|
|
const describeFn = options?.skip ? describe.skip : describe
|
|
describeFn(name(testCase), describeHandler.bind(null, testCase))
|
|
})
|
|
}
|