stak
Version:
110 lines (89 loc) • 2.51 kB
JavaScript
var assert = require("assert"),
Stak = require("../lib/stack.js");
suite("Stak", function () {
test("exists", function () {
assert(Stak);
assert(Stak.use);
assert(Stak.handle);
});
suite("use", function () {
test("use works", function () {
var s = instance(),
count = 0;
s.use(function () {
count++;
this.next(5);
});
s.use(function (i) {
count += i;
});
s.handle();
assert(count === 6);
});
});
suite("handle", function () {
test("floor", function (done) {
var s = instance(function () {
this.next(true);
});
s.handle({
floor: function (bool) {
assert(bool === true);
done();
}
})
});
test("default floor", function (done) {
var s = instance(function () {
this.next(true);
});
s.floor = function (bool) {
assert(bool === true);
done();
};
s.handle();
});
test("default ceil", function (done) {
var s = instance(function (bool) {
assert(bool === true);
done();
});
s.ceil = function () {
this.next(true);
};
s.handle();
})
test("ceil", function (done) {
var s = instance(function (bool) {
assert(bool === true);
done();
});
s.handle({
ceil: function () {
this.next(true);
}
})
});
test("context", function (done) {
var s = instance(function () {
assert(this.state === true);
done();
});
s.handle({ state: true });
});
test("pass other stacks", function (done) {
var s1 = instance(function () {
this.next(true);
});
var s = instance(s1, function (bool) {
assert(bool === true);
done();
});
s.handle();
});
});
});
function instance() {
var o = Object.create(Stak);
return o.constructor.apply(o, arguments);
}