Created
May 29, 2015 00:30
-
-
Save sprintingdev/fda0f3425a4b61b49693 to your computer and use it in GitHub Desktop.
jasmine-node Asynchronous callback unit testing
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
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); | |
} | |
}); | |
}; |
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
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