I need to simulate a long responseTime. My Moockjax is working – it delivers the right mock data. But my ajax call is done in the second i load the page, even if i set the responseTime to 20 seconds.
Do you have an idea?
I reduced my test page to the minimum, to exclude other potential sources of error here:
<!DOCTYPE HTML>
<html>
<head>
<script src="jquery.js"></script>
<script src="../jquery.mockjax.js"></script>
<title>MockJax Tests</title>
</head>
<body>
<h1>A MockJax test.</h1>
<p>Take a look into the console.</p>
<script>
$.mockjax({
url: "foo.html",
responseTime: 20000,
responseText: "Hi! I am mockjax."
});
$.ajax({
async: false,
url: 'foo.html',
success:function(data){
console.log(data);
},
error:function(data){
console.log('It doesn’t work that way :(');
}
});
</script>
</body>
</html>
I also wrote a test with CasperJS and Mockjax (inside of casper.evaluate). It is the same there.
Here is my CasperJS code
var casper = require("casper").create({
verbose: true,
logLevel: 'error',
clientScripts: ["node_modules/jquery-mockjax/jquery.mockjax.js"]
});
casper.on('remote.message', function(msg) {
this.echo('remote message caught: ' + msg);
})
casper.start('http://der-zyklop.de/', function() {
this.evaluate(function () {
$.mockjax({
url: "/blog/feed",
responseTime: 20000,
responseText: "Hi! I am mockjax!"
});
$.ajax({
async: false,
url: '/blog/feed',
success:function(data){
console.log(data);
},
error:function(data){
console.log('It doesn’t work that way :(');
}
});
});
});
casper.run();
If you have CasperJS installed, you should be able to run it by npm install jquery-mockjax
and then casperjs test.js
. It gives me this output in under 20 seconds:
I also wrote a blogarticle about it here.