Files
speckle-server/packages/server/test/assertionHelper.ts
T
Kristaps Fabians Geikins 7383779375 feat(server): registration (w/ and w/o invites) tests (#2567)
* WIP tests

* a couple of tests done

* most server registration tests done

* finalized tests

* lint fix

* added login tests too
2024-08-05 16:21:56 +03:00

28 lines
722 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>
) => {
testCases.forEach((testCase) => {
it(name(testCase), testHandler.bind(null, testCase))
})
}