assertThrows() limitations
assertThrows() seems to only filter on class name and message. Is there an assert function for checking whether code throws a DOMException with a specific name?
3 Replies
Ah I guess I can simply do:
I had missed that form of
assertThrows()
returns the error.
Now, it's an async call I have in my try/catch, and assertThrows()
doesn't support PromiseLike
…
I just want a std assert I can replace the following with:
I wish I could do
Made a feature request at https://github.com/denoland/deno_std/issues/3999
GitHub
[assert] support async code in assertThrows() · Issue #3999 · denol...
For synchronous code, it is possible to replace: try { doSomething() } catch (ex) { assertInstanceOf(ex, DOMException) assertEquals(ex.name, 'AbortError') } with just: const { name } = asse...
I wasn't able to find the answer to your question in the official Deno documentation. However, based on your message, it seems like you're looking for a way to assert that a specific type of
DOMException
is thrown with a particular name.
While I can't provide a direct answer from the documentation, I can suggest that if assertThrows()
does not meet your requirements, you might consider writing a custom assertion function to check for the specific DOMException
and its name. This could involve try-catch blocks to capture the exception and then assertions to check the name
property of the caught exception.
Please note that this advice is not based on the Deno documentation, and I would advise you to double-check the accuracy of this advice. If you need further assistance, you might want to explore community resources or the Deno manual for more information on error handling and custom assertions.