Skip to content

Instantly share code, notes, and snippets.

@Madhuka
Created December 8, 2013 15:41
Show Gist options
  • Save Madhuka/7859220 to your computer and use it in GitHub Desktop.
Save Madhuka/7859220 to your computer and use it in GitHub Desktop.
Jasmine with AJAX and spyon (Sample bank Version 2)
function Bank() {};
Bank.send = function (information){
$.ajax({
method: "POST",
url: "/data",
data: information
});
};
Bank.moneyTransfer = function (transferData){
$.ajax({
method: "POST",
url: "/data",
data: transferData
});
};
describe("Bank Information passing", function() {
it("Bank should send user name", function(){
spyOn($,"ajax");
var bankUserInformation = {"Bank User Name":"mahuka"};
Bank.send(bankUserInformation);
expect($.ajax).toHaveBeenCalledWith ({
method:"POST",
url:"/data",
data:{"Bank User Name":"mahuka"}
});
});
it("Bank money transfer", function(){
spyOn($,"ajax");
var moneyTransferInformation = {"from":"2345-1232-1232","to":"1212-5656-7898","amount":Math.random()};
Bank.moneyTransfer(moneyTransferInformation);
expect($.ajax).toHaveBeenCalledWith ({
method:"POST",
url:"/data",
data: moneyTransferInformation
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment