Tests if two types are exactly the same shape.
Demands the parameter evaluate to true.
Demands the parameter evaluate to false. Inverse of Expect.
Tests if a type is a valid array.
Tests if a given type would satisfy a given supertype.
Tests if the provided arguments resolve to equivalent TypeScript values.
Utility types for unit testing TypeScript types.
Types derived from and inspired by MichiganTypeScript/type-testing (GitHub) and Testing Types in TypeScript by Adam Rackis.
Since
0.1.0
Example
Your type tests should probably be in the same file as your Javascript tests (and not in your production code where those objects are defined). For this example, imagine we imported this function to test.
These values should also be tested by Jest/etc. for their values — and though this example is just looking at type testing, this lets us test the inferred return types at the same time.
Here’s how I would test these types. Add two types to Exactly to test that these types match. In rare cases you might use Satisfies.
Wrap your tests in either Expect or ExpectNot — if any of your tests fail, this is what will cause an error.