Skip to content

Commit

Permalink
Merge pull request #92 from unstoppablecarl/master
Browse files Browse the repository at this point in the history
init tests
  • Loading branch information
troutowicz committed Jun 2, 2015
2 parents 27bf661 + d8329b7 commit e508c8e
Showing 1 changed file with 113 additions and 0 deletions.
113 changes: 113 additions & 0 deletions test/init.js
Expand Up @@ -6,18 +6,24 @@ var stampit = require('../stampit'),
// Closure arguments

test('stamp.init() arguments are passed', function (t) {

var initStamp;
var stamp = stampit().init(function (opts) {
t.ok(opts, 'opts should be passed to init()');
t.ok(opts.instance, 'opts.instance should exist');
t.equal(typeof opts.instance, 'object', 'opts.instance should be object');
t.strictEqual(opts.instance, this, 'opts.instance === this');
t.ok(opts.stamp, 'opts.stamp should exist');
t.equal(typeof opts.stamp, 'function', 'opts.stamp should be function');
t.ok(opts.args, 'opts.args should exist');
t.ok(isArray(opts.args), 'opts.args should be array');
initStamp = opts.stamp;
});

stamp();

t.strictEqual(stamp, initStamp, 'opts.stamp === stamp returned');

t.end();
});

Expand Down Expand Up @@ -52,3 +58,110 @@ test('stamp.init() should assign arguments to `opts.args`', function (t) {

t.end();
});

test('stamp.init() can handle multiple init functions', function (t) {

var init1;
var init2;
var init3;

var stamp = stampit()
.init(function () {
init1 = true;
}).init(function () {
init2 = true;
}).init(function () {
init3 = true;
});

stamp();

t.ok(init1, 'init 1 fired');
t.ok(init2, 'init 2 fired');
t.ok(init3, 'init 3 fired');

t.end();
});

test('stamp.init() can handle multiple init functions assigned with array', function (t) {

var init1;
var init2;
var init3;

var stamp = stampit().init([
function () {
init1 = true;
},
function () {
init2 = true;
},
function () {
init3 = true;
}
]);

stamp();

t.ok(init1, 'init 1 fired');
t.ok(init2, 'init 2 fired');
t.ok(init3, 'init 3 fired');

t.end();
});

test('stamp.init() can handle multiple init functions assigned with object', function (t) {

var init1;
var init2;
var init3;

var stamp = stampit().init({
foo: function () {
init1 = true;
},
bar: function () {
init2 = true;
},
bam: function () {
init3 = true;
}
});

stamp();

t.ok(init1, 'init 1 fired');
t.ok(init2, 'init 2 fired');
t.ok(init3, 'init 3 fired');

t.end();
});

test('stamp.init() should call composed init functions in order', function (t) {

var result = [];

var stamp = stampit().init(function () {
result.push('a');
}).init(function () {
result.push('b');
}).init(function () {
result.push('c');
});

var stamp2 = stampit().init([
function(){
result.push('d');
},
function(){
result.push('e');
}
]);

var stamp3 = stampit.compose(stamp, stamp2);

stamp3();
t.deepEqual(result, ['a', 'b', 'c', 'd', 'e'], 'init called in order');

t.end();
});

0 comments on commit e508c8e

Please sign in to comment.