Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/palmerj3/jest-offline
Prevent Jest tests from hitting the network
https://github.com/palmerj3/jest-offline
Last synced: 12 days ago
JSON representation
Prevent Jest tests from hitting the network
- Host: GitHub
- URL: https://github.com/palmerj3/jest-offline
- Owner: palmerj3
- License: apache-2.0
- Created: 2017-01-17T01:48:28.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-04-29T23:04:02.000Z (7 months ago)
- Last Synced: 2024-09-20T12:08:01.928Z (about 2 months ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 29
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Jest-Offline
Jest-Offline is an addon to your Jest test suite which will fail tests that make network requests.
To install:
```
yarn add jest-offline
```To use:
```javascript
{
"jest": {
"setupFiles": [
"/node_modules/jest-offline"
]
}
}
```Any tests that make network requests will fail with a thrown exception.
## Why do this?
Fundamentally, unit tests should not make network requests. Unit tests should be as small as possible and test components in isolation whenever possible.
Any tests that rely on the network are inherently flaky and can put a strain on systems.
The best unit tests are tests that give the exact same result every single time you run the test. If they rely on network then that is simply impossible to achieve.
So jest-offline offers a simple way to:
1. Identify what tests are hitting the network
2. Prevent tests from hitting the networkYou could either use this locally in order to see what tests are hitting the network. Or you could enable this by default on CI so no new tests can be added that hit the network.