Skip to content
This repository has been archived by the owner on Mar 7, 2021. It is now read-only.

Commit

Permalink
removeFetch/DownloadCondition: added tests to confirm they throw prop…
Browse files Browse the repository at this point in the history
…erly
  • Loading branch information
venning committed Jul 12, 2017
1 parent f7e3bc4 commit 38f8e65
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions test/conditions.js
Expand Up @@ -42,6 +42,33 @@ describe("Fetch conditions", function() {
crawler._fetchConditions.length.should.equal(0);
});

it("should throw when it can't remove a fetch condition by ID", function() {
var crawler = makeCrawler("http://127.0.0.1:3000"),
condition = function() {},
conditionID = crawler.addFetchCondition(condition);

crawler._fetchConditions.length.should.equal(1);
(function () {
crawler.removeFetchCondition(-1);
}).should.throw();
(function () {
crawler.removeFetchCondition(conditionID + 1);
}).should.throw();
crawler._fetchConditions.length.should.equal(1);
});

it("should throw when it can't remove a fetch condition by reference", function() {
var crawler = makeCrawler("http://127.0.0.1:3000"),
condition = function() {};

crawler.addFetchCondition(condition);
crawler._fetchConditions.length.should.equal(1);
(function () {
crawler.removeFetchCondition(function() {});
}).should.throw();
crawler._fetchConditions.length.should.equal(1);
});

it("should provide fetch conditions with the right data", function(done) {
var crawler = makeCrawler("http://127.0.0.1:3000"),
fetchConditionCalled = false;
Expand Down Expand Up @@ -193,6 +220,33 @@ describe("Download conditions", function() {
crawler._downloadConditions.length.should.equal(0);
});

it("should throw when it can't remove a download condition by ID", function() {
var crawler = makeCrawler("http://127.0.0.1:3000"),
condition = function() {},
conditionID = crawler.addDownloadCondition(condition);

crawler._downloadConditions.length.should.equal(1);
(function () {
crawler.removeDownloadCondition(-1);
}).should.throw();
(function () {
crawler.removeDownloadCondition(conditionID + 1);
}).should.throw();
crawler._downloadConditions.length.should.equal(1);
});

it("should throw when it can't remove a download condition by reference", function() {
var crawler = makeCrawler("http://127.0.0.1:3000"),
condition = function() {};

crawler.addDownloadCondition(condition);
crawler._downloadConditions.length.should.equal(1);
(function () {
crawler.removeDownloadCondition(function() {});
}).should.throw();
crawler._downloadConditions.length.should.equal(1);
});

it("should provide download conditions with the right data", function(done) {
var crawler = makeCrawler("http://127.0.0.1:3000"),
downloadConditionCalled = false;
Expand Down

0 comments on commit 38f8e65

Please sign in to comment.