Skip to content

Instantly share code, notes, and snippets.

@sk8terboi87
Created May 20, 2014 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sk8terboi87/3ec81f06cfa62b2590a3 to your computer and use it in GitHub Desktop.
Save sk8terboi87/3ec81f06cfa62b2590a3 to your computer and use it in GitHub Desktop.
"use strict"
var MINI = require('minified');
var _=MINI._, $=MINI.$, $$=MINI.$$, EE=MINI.EE, HTML=MINI.HTML;
function Pinger(request) {
this.request = request;
}
Pinger.prototype.makeRequest = function(url) {
var promiseData = this.request(
'get',
url
);
return promiseData;
};
Pinger.prototype.processRequest = function(promiseData, successFn, errorFn) {
console.log(successFn);
promiseData.then(
_.bind(successFn, this),
_.bind(errorFn, this)
);
};
Pinger.prototype.onSuccess = function() {
console.log('e');
this.kickSuccess();
};
Pinger.prototype.onError = function() {
console.log('e1');
this.kickError();
};
Pinger.prototype.kickSuccess = function() {
console.log('me success :)');
};
Pinger.prototype.kickError = function() {
console.log('me error :(');
};
// TO RUN
// var p = new Pinger($.request);
// var promiseData = p.makeRequest('http://httpbin.org/get');
// p.processRequest(promiseData, p.onSuccess, p.onError);
describe("Pinger", function() {
var pinger;
beforeEach(function() {
pinger = new Pinger($.request);
});
afterEach(function() {
});
it('should call "kickSuccess" on succesfully call', function() {
successFn = jasmine.createSpy("successFn");
errorFn = jasmine.createSpy("errorFn");
var promiseData = _.promise();
pinger.processRequest(promiseData, pinger.onSuccess, pinger.onError);
// pinger.processRequest(promiseData, successFn, errorFn);
// Making Success
promiseData(true, []);
expect(successFn).toHaveBeenCalled();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment