Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions packages/toolkit/vitest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,6 @@ vi.stubGlobal('fetch', nodeFetch)
vi.stubGlobal('Request', Request)
vi.stubGlobal('Headers', Headers)

/**
* Compares two values to determine if they are instances of {@linkcode Error}
* and have the same {@linkcode Error.name | name}
* and {@linkcode Error.message | message} properties.
*
* @param actualError - The actual error to compare.
* @param expectedError - The expected error to compare against.
* @returns `true` if both values are instances of {@linkcode Error} and have the same {@linkcode Error.name | name} and {@linkcode Error.message | message}.
*
* @example
* <caption>#### __Pass: The actual error is an instance of `TypeError` with the same `message` ✔️__</caption>
*
* ```ts
* expect(consoleErrorSpy).toHaveBeenLastCalledWith(
* TypeError('endpointDefinition.queryFn is not a function'),
* )
* ```
*
* @example
* <caption>#### __Fail: The actual error is a `TypeError`, which is more specific than the expected generic `Error` ❌__</caption>
*
* ```ts
* expect(consoleErrorSpy).toHaveBeenLastCalledWith(
* Error('endpointDefinition.queryFn is not a function'),
* )
* ```
*
* @internal
*/
const areErrorsEqual = (actualError: unknown, expectedError: unknown) => {
if (actualError instanceof Error && expectedError instanceof Error) {
return (
actualError.name === expectedError.name &&
actualError.message === expectedError.message
)
}
}

expect.addEqualityTesters([areErrorsEqual])

beforeAll(() => {
server.listen({ onUnhandledRequest: 'error' })
})
Expand Down
Loading