2.0.2 • Published 3 years ago
fetch-reply-with v2.0.2
fetch-reply-with
Simplifies unit tests by intercepting fetch requests and returning mocked responses.
Install
npm install --save-dev fetch-reply-withUsage
require('fetch-reply-with'); // <- `fetch` is now globally available
// intercept GET http://orcascan.com and reply with...
fetch('http://orcascan.com', {
// regular fetch option
method: 'GET',
// add reply for this fetch
replyWith: {
status: 200,
body: 'Barcode Scanner app',
headers: {
'Content-Type': 'text/html'
},
delay: 500 // miliseconds to wait before responding (default = 0)
}
});
// execute fetch request
fetch('http://orcascan.com').then(function(res){
return res.text();
})
.then(function(text){
// text === `Barcode Scanner app`
});Couple of things to note:
- Requests not setup with
replyWithare executed as normal - A
replyWithcan be modified by redefining thereplyWith
Unit Tests
The project includes unit tests, to run the tests:
- Checkout
git clone https://github.com/john-doherty/fetch-reply-with - Navigate into project folder
cd fetch-reply-with - Install dependencies
npm install - Run the tests
npm test
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature - Commit your changes:
git commit -m 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request :)
Star the repo
If you find this useful please star the repo, it helps us prioritize fixes :raised_hands:
History
For change-log, check releases.
License
Licensed under MIT License © John Doherty
1.3.4
3 years ago
1.3.3
3 years ago
2.0.2
3 years ago
2.0.1
3 years ago
2.0.0
3 years ago
1.3.2
4 years ago
1.3.1
4 years ago
1.3.0
5 years ago
1.2.9
8 years ago
1.2.8
8 years ago
1.2.7
8 years ago
1.2.6
8 years ago
1.2.5
8 years ago
1.2.4
8 years ago
1.2.3
8 years ago
1.2.2
8 years ago
1.2.1
8 years ago
1.2.0
8 years ago
1.1.1
8 years ago
1.1.0
8 years ago
1.0.3
8 years ago
1.0.2
8 years ago
1.0.1
8 years ago
1.0.0
8 years ago