I am writing a test that supposedly should catch an exception
describe('unauthorized', () => {
const client = jayson.Client.http({
host: 'localhost',
port: PORT,
path: '/bots/uuid',
})
it('should return unauthorized response', async () => {
const t = async () => {
await client.request('listUsers', {})
}
expect(t()).toThrow(Error)
})
})
I am pretty sure that client.request
is throwing an exception but Jest says:
Received function did not throw
const test = async () => {
...
}
Is the correct way to check?
UPDATE
If I change to
expect(t()).toThrow(Error)
I got
expect(received).toThrow(expected)
Matcher error: received value must be a function
Received has type: object
Received has value: {}