Any reason to not put the expect inside the catch bloc ?
Yes. If it doesn't throw assertion wouldn't run, and the test would pass. You'd have to do
expect.assertions(1) try { await foo() } catch (e) { var error = e expect(error.message).toMatch(/foo/) }
Personally, I'd just go with
await expect(foo()).rejects.toThrow('foo') // Or, if final in the test: return expect(foo()).rejects.toThrow('foo') // doesn't require `async` `it`
(No need for expect.assertions(1) since the expect runs synchronously inline)
expect.assertions(1)
expect
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Any reason to not put the expect inside the catch bloc ?
Yes. If it doesn't throw assertion wouldn't run, and the test would pass.
You'd have to do
Personally, I'd just go with
(No need for
expect.assertions(1)
since theexpect
runs synchronously inline)