Skip to content

Instantly share code, notes, and snippets.

@panSarin
Created January 20, 2015 12:51
Show Gist options
  • Save panSarin/3ebfb26550854267c972 to your computer and use it in GitHub Desktop.
Save panSarin/3ebfb26550854267c972 to your computer and use it in GitHub Desktop.
Jasmine presentation source code - problem with response method
MyRequests.prototype.display_response = function(response){};
MyRequests.prototype.get_topics = function(bstokJS_stage) {
$.ajax({
type: 'GET',
url: 'https://gist.githubusercontent.com/panSarin/3d0e3080ee36e3b82c79/raw/8f496cfd22a766644b0ee834afb813ca1790c304/bstokjs'+bstokJS_stage+'.json',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: this.display_response()
});
};
describe('Ajax request', function(){
var my_requests;
beforeEach(function() {
jasmine.Ajax.install();
my_requests = new MyRequests();
});
afterEach(function() {
jasmine.Ajax.uninstall();
});
it("request url should depends on given bstokJS stage ", function() {
my_requests.get_topics('1');
spyOn(my_requests, 'display_response');
request = jasmine.Ajax.requests.mostRecent();
expect(request.url).toBe('https://gist.githubusercontent.com/panSarin/3d0e3080ee36e3b82c79/raw/8f496cfd22a766644b0ee834afb813ca1790c304/bstokjs1.json');
expect(my_requests.display_response).not.toHaveBeenCalled();
request.response({
"status": 200,
"contentType": 'text/plain',
"responseText": 'awesome response'
});
});
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Jasmine Spec Runner v2.1.3</title>
<link rel="shortcut icon" type="image/png" href="lib/jasmine-2.1.3/jasmine_favicon.png">
<link rel="stylesheet" href="lib/jasmine-2.1.3/jasmine.css">
<script src="lib/jasmine-2.1.3/jasmine.js"></script>
<script src="lib/jasmine-2.1.3/jasmine-html.js"></script>
<script src="lib/jasmine-2.1.3/boot.js"></script>
<!-- ajax testing -->
<script src="lib/jasmine-2.1.3/jquery-2.1.3.min.js"></script>
<script src="lib/jasmine-2.1.3/mock-ajax.js"></script>
<!-- include source files here... -->
<script src="src/MyRequests.js"></script>
<!-- include spec files here... -->
<script src="spec/MyRequestsSpec.js"></script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment