Files
speckle-server/packages/server/test/assertionHelper.ts
T
Kristaps Fabians Geikins 51579b76ef fix(server): various fixes related to subs + further improved utils + way quicker tests (#3573)
* 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?
2024-12-02 13:30:24 +02:00

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))
})
}