Skip to content

Commit

Permalink
dom parsing test
Browse files Browse the repository at this point in the history
build support
  • Loading branch information
digitaldesigndj committed Aug 16, 2023
1 parent c925b72 commit 3856c76
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.env
.env.*
_fresh
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"run": "DENO_DEPLOYMENT_ID=$(git rev-parse --short HEAD) deno run -A --unstable main.ts",
"test": "deno test -A --unstable",
"build": "deno run -A dev.ts build",
"preview": "deno run -A main.ts"
"preview": "deno run -A --unstable main.ts"
},
"compilerOptions": {
"jsx": "react-jsx",
Expand Down
21 changes: 15 additions & 6 deletions test/4_fetch_test_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { startFreshServer } from "$fresh/tests/test_utils.ts"
import { BASE_URL } from "@/utils/config.js"
import { assert, assertEquals } from "$std/assert/mod.ts"
import { Status } from "$std/http/http_status.ts"
import { DOMParser } from "https://deno.land/x/deno_dom/deno-dom-wasm.ts"

const myTestWrapper =
(args: string[]) => (theTests: any) => async (t: Deno.TestContext) => {
Expand Down Expand Up @@ -31,11 +32,19 @@ Deno.test(
sanitizeOps: false,
},
fetchTestWrapper(async (t: Deno.TestContext) => {
await t.step("The index page returns a 200 and a 'Welcome'", async () => {
const response = await fetch(`${BASE_URL}`)
assertEquals(response.status, Status.OK)
const text = await response.text()
assert(text.includes("Welcome"))
})
await t.step(
"The index page returns 200, a 'Welcome', HTML Document, and more",
async () => {
const response = await fetch(`${BASE_URL}`)
assertEquals(response.status, Status.OK)
const text = await response.text()
assert(text.includes("Welcome"))
const document = new DOMParser().parseFromString(text, "text/html")
assert(document)
const h1 = document.querySelector("h1")
assert(h1)
assertEquals(h1.textContent, "Hello")
},
)
}),
)

0 comments on commit 3856c76

Please sign in to comment.