Error handling in test not capturing specific error message
it('should return the error', async () => {
const mockError = new Error('Failed to load markets')
const mockLoadMarkets = spyOn(
exchange,
'loadMarkets',
).mockImplementationOnce(async () => {
return await Promise.reject(mockError)
})
expect(async () => {
await Fx.runPromise(loadMarketsE(exchange))
}).toThrowError(mockError)
mockLoadMarkets.mockRestore()
}) it('should return the error', async () => {
const mockError = new Error('Failed to load markets')
const mockLoadMarkets = spyOn(
exchange,
'loadMarkets',
).mockImplementationOnce(async () => {
return await Promise.reject(mockError)
})
expect(async () => {
await Fx.runPromise(loadMarketsE(exchange))
}).toThrowError(mockError)
mockLoadMarkets.mockRestore()
})I get:
Expected message: "Failed to load markets"
Received message: "An unknown error occurred"Expected message: "Failed to load markets"
Received message: "An unknown error occurred"Why is this? I expected the specific error but got a generic one.
