Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
70 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
dist | ||
test |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import chai from "chai"; | ||
import Queue from "../src/"; | ||
|
||
describe("queue-promise", function () { | ||
const expect = chai.expect; | ||
|
||
let count = 0; | ||
let queue = new Queue({ | ||
concurrency: 1, | ||
interval: 500 | ||
}); | ||
|
||
const reject = () => new Promise((resolve, reject) => reject("Error")); | ||
const resolve = () => new Promise((resolve, reject) => resolve("Success")); | ||
|
||
describe("add(asyncTask)", function () { | ||
it("should add a new task if valid", function () { | ||
queue.add(reject); | ||
queue.add(resolve); | ||
|
||
expect(queue.collection.size).to.equal(2); | ||
}); | ||
|
||
it("should reject a new task if not valid", function () { | ||
try { | ||
expect(queue.add(true)).to.throw(); | ||
} catch (err) { | ||
expect(err).to.be.an.instanceof(Error); | ||
expect(err.message).to.equal("You must provide a function, not boolean."); | ||
} | ||
}); | ||
}); | ||
|
||
describe("remove(key)", function () { | ||
it("should remove a registered task", function () { | ||
queue.remove(0); | ||
queue.remove(1); | ||
|
||
expect(queue.collection.size).to.equal(0); | ||
}); | ||
}); | ||
|
||
describe("on(event, callback)", function () { | ||
it("should handle events", function () { | ||
queue.on("resolve", function(data){count += 1}); | ||
queue.on("reject", function(error){count += 1}); | ||
}); | ||
}); | ||
|
||
describe("start()", function () { | ||
it("should handle events", function (done) { | ||
queue.add(reject); | ||
queue.add(resolve); | ||
queue.start(); | ||
|
||
setTimeout(function () { | ||
expect(count).to.equal(2); | ||
done(); | ||
}, 1250); | ||
}); | ||
}); | ||
}); |