If you are interested in server side rendering, then both deno-dom and are better choices. If you are trying to run code in a “virtual” browser that needs to be standards based, then it is possible that jsdom is suitable for you.
While jsdom works under the Deno CLI, it does not type check. This means you
have to use the --no-check=remote
option on the command line to avoid
diagnostics stopping the execution of your programme.
Having sound typing in an editor requires some changes to the workflow as well, as the way jsdom types are provided are declared as a global type definition with a globally named module, as well as leveraging the built in types from the built-in DOM libraries.
This means if you want strong typing and intelligent auto-completion in your editor while using the Deno language server, you have to perform some extra steps.
Defining an import_map.json
Setting up a configuration file
You will want to set up a deno.jsonc
configuration file in the root of your
workspace with both TypeScript library information as well as specifying the
import map defined above:
"lib": [
"deno.ns",
"dom",
]
},
"importMap": "./import_map.json"
This example will take a test string and parse it as HTML and generate a DOM structure based on it. It will then query that DOM structure, picking out the first heading it encounters and print out the text content of that heading:
```ts, ignore import { JSDOM } from “jsdom”; import { assert } from “https://deno.land/std@0.132.0/testing/asserts.ts“;
Hello from Deno
`, { url: ““, referrer: “https://example.org/“, contentType: “text/html”, storageQuota: 10000000, }, );const h1 = document.querySelector(“h1”); assert(h1);
console.log(h1.textContent); ```