Release Notes
This page lists breaking changes and notable new features. Please be sure to read the release notes before upgrading from previous version.
The detailed changelog can be found in TSTyche repository on GitHub (opens in a new tab).
TSTyche 2.1
TSTyche 2.1 ships with the new .toAcceptProps()
matcher.
Matchers
.toAcceptProps()
Checks if the JSX component accepts props of the given type.
import { expect, test } from "tstyche";
interface ButtonProps {
text: string;
type?: "reset" | "submit";
}
function Button({ text, type }: ButtonProps) {
return <button type={type}>{text}</button>;
}
test("accepts props?", () => {
expect(Button).type.toAcceptProps({ text: "Send" });
expect(Button).type.toAcceptProps({ text: "Clear", type: "reset" as const });
expect(Button).type.not.toAcceptProps({ text: "Download", type: "button" as const });
expect(Button).type.not.toAcceptProps({});
});
This is a work in progress feature. Generic components are not yet supported.
TSTyche 2.0
TSTyche 2.0 ships with more matchers, performance refinements and watch mode.
Requirements
The minimum required Node.js version is 16.14
. It is recommended to use the latest Long Term Support (LTS) release.
Testing on specific version of TypeScript requires Node.js 18 or later. The global fetch()
(opens in a new tab) method is now used to fetch the typescript
package metadata from the registry.
Configuration
testFileMatch
The logic of glob pattern matching is reworked. Current implementation allows selecting all matching paths including .json
or .mdx
files.
For instance, to avoid selecting the __tests__/tsconfig.json
as a test file:
- Emitter.ts
- Semaphore.ts
- tsconfig.json
A *.ts
must be added to the pattern:
{
- "testFileMatch": ["__tests__"]
+ "testFileMatch": ["__tests__/*.ts"]
}
Test Runner
--watch
Watch mode is added. Current implementation is watching the TSTyche configuration file and the test files for changes.
tstyche --watch
Files are watched recursively using the fs.watch()
(opens in a new tab) method that relies on file system events.
In some cases this feature is not available (opens in a new tab). For example, it does not work on network file systems. Also note that recursive watch support was added for the Linux systems only since Node.js 20.
Matchers
.toBe()
.toBe()
is the new name of .toEqual()
.
import { expect } from "tstyche";
- expect<{ a: string }>().type.toEqual<{ a: string }>();
+ expect<{ a: string }>().type.toBe<{ a: string }>();
- expect<{ a: string }>().type.not.toEqual<{ b: number }>();
+ expect<{ a: string }>().type.not.toBe<{ b: number }>();
The new name simplifies swapping between the primitive type matchers and .toBe()
. For example, replacing .toBeString()
with .toBe<string | undefined>()
looks more clear than before.
.toBeAssignableTo()
.toBeAssignableTo()
is a new matcher, it checks if the source type is assignable to the target type. The opposite of .toBeAssignableWith()
.
import { expect } from "tstyche";
expect<{ a: string; b: number }>().type.toBeAssignableTo<{ a: string }>();
expect<{ a: string }>().type.not.toBeAssignableTo<{ a: string; b: number }>();
.toBeAssignableWith()
.toBeAssignableWith()
is the new name of .toBeAssignable()
, it checks if the source type is assignable with the target type. The opposite of .toBeAssignableTo()
.
import { expect } from "tstyche";
- expect<{ a: string }>().type.toBeAssignable<{ a: string; b: number }>();
+ expect<{ a: string }>().type.toBeAssignableWith<{ a: string; b: number }>();
- expect<{ a: string; b: number }>().type.not.toBeAssignable<{ a: string }>();
+ expect<{ a: string; b: number }>().type.not.toBeAssignableWith<{ a: string }>();
The .toBeAssignableTo()
and .toBeAssignableWith()
matchers allow checking assignability both ways and make it easier to understand what is being tested.
Which one to use? It depends on what you are testing. A good rule of thumb is to keep the type under test on the left hand side of the assertion.