jest-helpers
Tests should be living documentation for your code, but often test descriptions get out of sync with your code. This library helps keep them in sync using TypeScript.
Benefits
- When you rename a class, the name of your test for it will automatically update
- When you rename any of the following, your test will get a TypeScript error until you update your test:
- A method on a class
- A field on a class
- An exported function inside a module
- Has useful functions for creating mocks:
partialOf<T>(partial: Partial<T>): T
deepPartialOf<T>(partial: DeepPartial<T>): T
Install
npm install jest-helpers --save-dev
Usage
./greeter.ts
./greeter.test.ts
;;; describeClassGreeter,; describeFunctiongreeterModule, 'showGreeting',;
Running jest --verbose
will output something like
example/greeter.ts
Greeter
getGreeting
✓ should return a personalised greeting (4ms)
showGreeting
✓ should log greeting to the console (2ms)
If you rename your Greeter
class, it will automatically update the test description.
If you rename your Greeter.getGreeting
method, you will get a TypeScript error in your test until you update your test to match the new name.
If you rename your showGreeting
function, you will get a TypeScript error in your test until you update your test to match the new name.
Contributing
Got an issue or a feature request? Log it.
Pull-requests are also welcome. 😸