Comments (2)
var mock = require('xhr-mock');
//replace the real XHR object with the mock XHR object
mock.setup();
//create a mock response for all POST requests with the URL http://localhost/api/user
mock.post('http://localhost/api/user', function(req, res) {
return res.timeout(true); //simulate a timeout
});
//create an instance of the (mock) XHR object and use as per normal
var xhr = new XMLHttpRequest();
...
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
//when you're finished put the real XHR object back
mock.teardown();
}
}
^^^ doesn't work for you? https://github.com/jameslnewell/xhr-mock#timeout--boolnumber
from xhr-mock.
Thanks a lot for your reply! :)
I seriously don't know how I missed that function. Works perfectly. 🎉
from xhr-mock.
Related Issues (20)
- Test URL with Query string HOT 1
- Is there a method similar with fetchMock.flush? HOT 8
- Responsetype "arraybuffer" not implemented correctly
- Handler inside createMockFunction never gets triggered. HOT 1
- Simulating a timeout causes Jest to throw a ECONNREFUSED error but the tests pass HOT 1
- feat: support verbose log in dev mode? HOT 1
- Support params match?
- Jest passes but xhr-mock logs the Jest expectation failure to console.error
- Feature request for sending/setting cookies automatically when present.
- Is there a way to overwrite a request again?
- Request headers are not reset between .open() calls
- Unclear how to test upload progress HOT 1
- xhr.readyState = 2 // xhr.status = 0 HOT 1
- Examples for mocks set up using regular expressions HOT 1
- Add xhrMock.all method for all of get, post, put, patch, delete HOT 1
- Add url masks please HOT 2
- New release HOT 2
- sequence is not a function HOT 2
- Latest release doesn't published HOT 1
- Release latest changes to npm HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xhr-mock.