D
Deno

help

assertThrows() limitations

Jjcayzac12/20/2023
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? Ah I guess I can simply do:
const { name } = assertThrows(() => { … }, DOMException))
assertEquals(name, 'AbortError')
const { name } = assertThrows(() => { … }, DOMException))
assertEquals(name, 'AbortError')
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:
try {
await
} catch (ex) {
assertInstanceOf(ex, DOMException)
assertEquals(ex.name, 'AbortError')
}
try {
await
} catch (ex) {
assertInstanceOf(ex, DOMException)
assertEquals(ex.name, 'AbortError')
}
I wish I could do
const { name } = await assertThrows(async () => { … }, DOMException))
assertEquals(name, 'AbortError')
const { name } = await assertThrows(async () => { … }, DOMException))
assertEquals(name, 'AbortError')
Jjcayzac12/20/2023
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...
DAHDeno AI Helper12/20/2023
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.

Looking for more? Join the community!

Recommended Posts
LSP/VSCode stops workingI'm having issues in my fresh project time to time it stops working and I have to restart it or vscoCan the listeners for messages from Deno Deploy Queues timeout?Can the listeners for messages from Deno Deploy Queues timeout like Vercel serverless functions? AreHow to get the path to the compiled binary?`import.meta.url` and `Deno.mainModule` are used to get the current script, but after a binary is crHow to get `require.main.filename` like Node as DenoI am making a module to be published on deno.land/x. I want the user to put a file describing the coChange Web Worker Permissions after the Worker StartedHello, I was wondering if it is possible to change/update the permissions of a web worker after it Missing transpiled source codeI'm trying to generate coverage for my project and I'm getting the following: ``` deno task coverageTrouble validating a requestHi there! I'm trying to validate a Discord HTTP request, but I don't know how to do it (https://discHow to deploy to Deno Deploy from a Github repository's subdirectory?I read somewhere that you can deploy from a subdirectory, but I can't find any documentation on how Convert to exeI have made my Javascript program into an exe with deno: https://docs.deno.com/runtime/manual/tools/Manual deployment promotion + long lived preview deploymentsHello! I am working on a deployment pipeline and have a few questions: 1. Is there a way to promoteIs there a way to get deno coverage information in a vscode lens?If I run my tests with coverage enabled, can I get some visual feedback in vscode?Performance QuestionI have a Deno application, which creates API endpoint, and uses mongodb. Now I want to host this on Is there a way to get a server's SSL certificate's public information with Deno?This is available in Node with `getPeerCertificate()` but not in Deno's Node compatibility layer - iInvalidData: No certificates found in cert fileHello! Following up from a previous help post here, https://discord.com/channels/684898665143206084/