This library provides commands to execute TSDoc @example tags in Typescript.
We also have a Visual Studio Code extension that uses this library directly from the IDE:
npx the-real-doctest test src/lib/utils.ts
Expression statements with ==, !=, === or !== will be checked for equality
// src/lib/utils.ts
/**
* @example f(0) == 10
* @example f(0) != 10 // This should fail
* @example f(10) == 20
* @example f(20) != 20
* @example f(20) == 20 // This should fail
*/
function f(x: number) {
return x + 10
}
Output:
3 doctests succeeded
2 doctests failed
At src/lib/utils.ts:3
>> 10 != 10
At src/lib/utils.ts:6
>> 30 == 20
npx the-real-doctest --help
Install the library as a dev dependency with the package manager of your choice
Then, run npx the-real-doctest install
.