I have attempted try many time but it always not work. I using Mocha unit test. This is my codes unit test:
var expect = require("expect");
var jQuery = require("jquery");
var sinon = require("sinon");
describe("SinonFakeServerWithJasmine", function() {
var server;
beforeEach(function() {
server = sinon.fakeServer.create();
});
afterEach(function() {
server.restore();
});
it("should fake a jQuery ajax request", function() {
server.respondWith("GET", "/something", [200, {
"Content-Type": "application/json"
},
'{ "stuff": "is", "awesome": "in here" }'
]);
jQuery.ajax({
url: "/something",
success: function() {
console.log("success");
},
error: function(err) {
console.log(err);
}
});
server.respond(); // Process all requests so far
});
});
==> And this is log error Jquery.ajax
{ readyState: 0,
getResponseHeader: [Function],
getAllResponseHeaders: [Function],
setRequestHeader: [Function],
overrideMimeType: [Function],
statusCode: [Function],
abort: [Function],
state: [Function],
always: [Function],
then: [Function],
promise: [Function],
pipe: [Function],
done: [Function],
fail: [Function],
progress: [Function],
complete: [Function],
success: [Function],
error: [Function],
status: 0,
statusText: 'TypeError: Invalid URL' }
I don't know why it error like that. I not use expect due to it unnecessary in my case, I want to test sinon with mocha Thank everyone have spent time read.
Aucun commentaire:
Enregistrer un commentaire