Skip to content

Instantly share code, notes, and snippets.

@sprintingdev
Created May 29, 2015 00:30
Show Gist options
  • Save sprintingdev/fda0f3425a4b61b49693 to your computer and use it in GitHub Desktop.
Save sprintingdev/fda0f3425a4b61b49693 to your computer and use it in GitHub Desktop.
jasmine-node Asynchronous callback unit testing
var request = require("require"); //request npm module
var Scraper = function() {
};
Scraper.prototype.scrape = function(url, callback) {
request(url, function responseCallback(error, response, html) {
if(error) {
callback(error);
} else {
console.log(html);
callback(null, html);
}
});
};
var scraper = require("scraper");
jasmine.getEnv().defaultTimeoutInterval = 10000;
describe("scraper", function () {
it("should be able to scrape google.com", function(done) {
scraper.scrape("http://google.com", function(error, html) {
if(!error){
expect(html).not.toBe(undefined);
done();
} else {
done(error);
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment