the following shim (polyfill) defines a simple standalone Deno.Test-like replacement for non-deno environments.
the only two things implemented here are:
test: Deno.Test function.
step: Deno.TestContext interface, which is passed onto your test-function that you feed to Deno.test.
Note
make sure that your test-function's body is side-effect free if you will be using async test functions in parallel.
otherwise, always perform a top-level await on all Deno.tests.
deno itself waits for all async tests to end their execution, so we don't have to write await before every Deno.test.
however, you don't get that luxury in the browser or other runtimes.
thus, you should alwaysawait your calls to Deno.test if you wish to use this shim/polyfill.
Example
// adapting a deno-native test file to become browser compatible:
- Deno.test("my test", (t): Promise => {
+ await Deno.test("my test", (t): Promise => {
// do the test
})
the following shim (polyfill) defines a simple standalone
Deno.Test-like replacement for non-deno environments.the only two things implemented here are:
test: Deno.Testfunction.step: Deno.TestContextinterface, which is passed onto your test-function that you feed toDeno.test.make sure that your test-function's body is side-effect free if you will be using
asynctest functions in parallel. otherwise, always perform a top-level await on allDeno.tests. deno itself waits for all async tests to end their execution, so we don't have to writeawaitbefore everyDeno.test. however, you don't get that luxury in the browser or other runtimes. thus, you should alwaysawaityour calls toDeno.testif you wish to use this shim/polyfill.Example