Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dgreene1/typesafejestspy
DEPRECATED-- Jest now includes types. Former description: Helps you write faster spies by automatically inferring the real implementation's type signature
https://github.com/dgreene1/typesafejestspy
jest spies typescript
Last synced: 4 months ago
JSON representation
DEPRECATED-- Jest now includes types. Former description: Helps you write faster spies by automatically inferring the real implementation's type signature
- Host: GitHub
- URL: https://github.com/dgreene1/typesafejestspy
- Owner: dgreene1
- License: gpl-3.0
- Created: 2018-12-14T17:57:21.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-10-27T20:43:03.000Z (over 4 years ago)
- Last Synced: 2024-10-04T21:38:09.138Z (4 months ago)
- Topics: jest, spies, typescript
- Language: TypeScript
- Homepage:
- Size: 22.5 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DEPRECATED: Yay! Jest has been [rewritten in TypeScript](https://github.com/facebook/jest/commit/be2703c103b63850a7a8fc244edf8e3c7798a9f3), so you no longer need to use this library! Enjoy the beautiful types of Jest.
## typeSafeJestSpy
A _very thin_ layer that helps you write faster spies by automatically inferring the real implementation's type signature### Why would you use this?
* Have you ever made a spy for entirely the wrong function?
* Have you ever returned bad data from a spy by accident?
* i.e. you knew that the method you were replacing was supposed to return a string... but you accidentally returned a number?Who would want false-positive unit tests? Accidental mistakes with spies are a thing of the past with typeSafeJestSpy! :)
### How do you use this?
* Please see the unit tests in the test folder for usage examplesSimply send your Jest spy into a function of this library and then the following Jest spy functions will require you to return the correct type:
* `mockImplementation`
* `mockImplementationOnce`
* `mockResolvedValue`
* `mockResolvedValueOnce`### Caveats
Please see the version of Jest in my package.json to see what this micro-library thinks is the way that Jest behaves. If your version of Jest is wildly different, then* you might get irregular behavior.
* you might find that Jest has introduced a type-safe version itself, in which case this library would no longer be required