It turns out that this function isn't really helpful, and has compatibility issues with Bun, tsx and browsers, it will be removed in the future.
import { default } from "https://deno.land/x/ayonli_jsext@v0.9.72/esm/example.js";
Inspired by Golang's Example as Test design, creates a function that
carries example code with // output:
comments, when the returned function
is called, it will automatically check if the actual output matches the one
declared in the comment.
The example function receives a customized console
object which will be
used to log outputs instead of using the built-in console
.
NOTE:
This function is used to simplify the process of writing tests, currently,
it does not work in Bun, tsx and browsers, because Bun hasn't implement
the Console
constructor and removes comments during runtime, tsx also
remove comments, and the function depends on Node.js built-in modules.
Examples
Example 1
Example 1
import example from "@ayonli/jsext/example";
it("should output as expected", example(console => {
console.log("Hello, World!");
// output:
// Hello, World!
}));