githubEdit

Testing

Deno has a built-in test runner that you can use for testing JavaScript or TypeScript code.

Lets start with an example all_tests.js

import {assertEquals} from "https://deno.land/std@0.199.0/assert/mod.ts";

Deno.test("url test", ()=>{
	const url = new URL("./foo.js", "https://deno.land")
	assertEquals(url.href, "htts://deno.land/foo.js");
})
deno test all_tests.js

"Deno.test" function takes two parameters, 1. Test name 2. Callback function to execute

We can specify extra configurations as a new parameter in json format deno.json

{
	"imports":{
		"assertTest" : "https://deno.land/std@0.199.0/assert/mod.ts",
		"asyncTest" : "https://deno.land/std@0.199.0/async/delay.ts",
		"Postgres" : "https://deno.land/x/postgres@v0.15.0/mod.ts",
	}
}

tests.js


Async Testing


Test Example

Example output:

Test steps must be awaited before the parent test/step function resolves or you will get a runtime error Test steps cannot be run concurrently unless sanitizers on a sibling step or parent test are disabled If nesting steps, ensure you specify a parameter for the parent step

Last updated