51579b76ef
* fixed test util throwing + added new tests * more tests * more tests * various model tests * version tests * removed shitty old tests * lint fix * workspaceProjectsUpdated test * workspace updated on invite * workspace subs support team changes * tests fix * test fix hopefully?
35 lines
862 B
TypeScript
35 lines
862 B
TypeScript
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
import { MaybeAsync, ensureError } from '@speckle/shared'
|
|
import { AssertionError } from 'chai'
|
|
import { it } from 'mocha'
|
|
|
|
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 sklipped
|
|
*/
|
|
skip: boolean
|
|
}>
|
|
) => {
|
|
testCases.forEach((testCase) => {
|
|
const itFn = options?.skip ? it.skip : it
|
|
itFn(name(testCase), testHandler.bind(null, testCase))
|
|
})
|
|
}
|