Created
May 20, 2014 17:20
-
-
Save sk8terboi87/3ec81f06cfa62b2590a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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