✅ Equality test with enforced legibility (based on RITEway and inspired by uvu).
Write:
import { suite } from "@vangware/test";
const add = (addend2: number) => (addend1: number) => addend1 + addend2;
export default suite([
{
given: "a 1 and a 2",
must: "return 3",
received: add(2)(1),
wanted: 3
},
{
given: "a 1 and a -2",
must: "return -1",
received: add(-2)(1),
wanted: -1
}
])("Example suite name (optional)");
Then run:
@vangware/test
If let's say the first test fails, the error reads something like this:
[FAIL] Example suite name (optional)
> Given a 1 and a 2, must return 3.
Received: 4
Wanted: 3
Documentation can be found HERE. It is auto-generated with typedoc based on the JSDocs and the types in the source. Shouldn't be necessary to read this, code editors like VSCode integrate the documentation in the UI.
Changelog can be found HERE.
Test coverage can be found HERE.
Promise import of a file containing a suite.
Output object given by a suite.
Array of failed tests.
Name of the test suite.
Array of passed tests.
Object that describes a test.
String explaining the given value.
String explaining what the test must return.
Value being tested.
Expected value.
Output of the test function.
Comma character (to avoid repetition).
Empty string.
Fail message with colors.
Indent for string output (used by object and array output).
Pass message with colors.
Unwanted comment (// Unwanted
in red text).
Return array with 1 level flatted.
Check if all the items in an array are TestResult
s.
Maps trough and array of strings and add indent to each item.
Join array with a comma followed by a space.
Join array with new lines.
Comment for missing items.
Maps using promiseWrap
.
Applies stringify
to every value in the given array.
Map given array of tests.
Takes an array of TestResult
and returns an array of strings.
Filter tests results in a tuple [passed, failed]
.
Comment for wanted items.
Takes a title and a value and turns it into an inline comment.
Color/style formatter for the text.
Compare two values and show the differences in different ways.
The wanted value type.
Wanted value.
Takes a boolean to know if this is the last item, and a source array and returns a string for matching items.
Takes a source array and returns a string for missing items.
Type of the items in the arrays being compared.
Source array of missing items.
Takes a boolean to know if the paren is in it's last item, and a source array and returns a string of unwanted elements.
Last item of the parent.
Compare two arrays and displays the differences (unwanted, missing and matching items).
The wanted value type.
Wanted array.
Compare two objects and displays the differences (unwanted, missing and matching items).
The wanted value type.
Wanted object.
Compares two primitive values.
The wanted value type.
Wanted value.
Checks if given TestResult
passed.
The actual type of the value.
Check if given value is a SuiteResult
object.
Value to check.
Check if given value is a TestResult
object.
Value to check.
Maps trough an array and sets an argument to true
when is the last item.
Type of the items in the array.
Output type after mapping.
Mapping function with last
boolean argument.
Given a value that could be either a promise or a value, return the value wrapped in a promise.
Value or Promise value.
Promise of that value.
Stringifies value reliably (using JSON.stringify
).
Type of the Source value to be transformed into string.
Source value to be stringified.
Creates a new test suite (array of tests).
The value being checked in the test.
List of test descriptions.
Import a file that exports a suite
.
File path to load from.
Takes a SuiteResult
object and returns a stringified version of it.
Takes an array of SuiteResult
and returns an array of strings.
Imports all the suites of the given array of paths.
Array of file paths.
Takes a Test
object and returns a TestResult
object.
Value being tested.
Takes a TestResult
and returns the name of the test.
Takes a TestResult
and returns a stringified version of it.
TestResult to generate the string from.
Generated using TypeDoc
Value tha can be possibly wrapped in a Promise.