MCPcopy Create free account
hub / github.com/Effect-TS/effect / throws

Function throws

packages/vitest/src/utils.ts:163–179  ·  view source on GitHub ↗
(thunk: () => void, error?: Error | ((u: unknown) => undefined), ..._: Array<never>)

Source from the content-addressed store, hash-verified

161 * @since 4.0.0
162 */
163export function throws(thunk: () => void, error?: Error | ((u: unknown) => undefined), ..._: Array<never>) {
164 try {
165 thunk()
166 } catch (e) {
167 if (error !== undefined) {
168 if (Predicate.isFunction(error)) {
169 error(e)
170 } else if (error) {
171 deepStrictEqual(e, error)
172 } else {
173 throw e
174 }
175 }
176 return
177 }
178 fail("Expected to throw an error")
179}
180
181/**
182 * Asserts that `thunk` throws or returns a rejected promise, optionally checking the failure value against an expected `Error` or validation function.

Callers

nothing calls this directly

Calls 3

deepStrictEqualFunction · 0.70
failFunction · 0.70
errorFunction · 0.50

Tested by

no test coverage detected