| 1 |
'use strict'; |
| 2 |
|
| 3 |
var expect = require('expect'); |
| 4 |
|
| 5 |
var Registry = require('../'); |
| 6 |
|
| 7 |
function noop() {} |
| 8 |
|
| 9 |
describe('undertaker-registry', function() { |
| 10 |
|
| 11 |
describe('constructor', function() { |
| 12 |
|
| 13 |
it('can be constructed with new', function(done) { |
| 14 |
var reg = new Registry(); |
| 15 |
expect(reg.get).toBeA('function'); |
| 16 |
expect(reg.set).toBeA('function'); |
| 17 |
expect(reg.tasks).toBeA('function'); |
| 18 |
done(); |
| 19 |
}); |
| 20 |
|
| 21 |
it('can be constructed without new', function(done) { |
| 22 |
var reg = Registry(); |
| 23 |
expect(reg.get).toBeA('function'); |
| 24 |
expect(reg.set).toBeA('function'); |
| 25 |
expect(reg.tasks).toBeA('function'); |
| 26 |
done(); |
| 27 |
}); |
| 28 |
}); |
| 29 |
|
| 30 |
describe('init', function() { |
| 31 |
|
| 32 |
it('is a noop', function(done) { |
| 33 |
var reg = new Registry(); |
| 34 |
expect(reg.init).toBeA('function'); |
| 35 |
done(); |
| 36 |
}); |
| 37 |
}); |
| 38 |
|
| 39 |
describe('get', function() { |
| 40 |
|
| 41 |
it('returns a task from the registry', function(done) { |
| 42 |
var reg = new Registry(); |
| 43 |
reg._tasks.test = noop; |
| 44 |
expect(reg.get('test')).toEqual(noop); |
| 45 |
done(); |
| 46 |
}); |
| 47 |
}); |
| 48 |
|
| 49 |
describe('set', function() { |
| 50 |
|
| 51 |
it('registers a task', function(done) { |
| 52 |
var reg = new Registry(); |
| 53 |
reg.set('test', noop); |
| 54 |
expect(reg._tasks.test).toEqual(noop); |
| 55 |
done(); |
| 56 |
}); |
| 57 |
|
| 58 |
it('returns the task (useful for inheriting)', function(done) { |
| 59 |
var reg = new Registry(); |
| 60 |
var task = reg.set('test', noop); |
| 61 |
expect(task).toEqual(noop); |
| 62 |
done(); |
| 63 |
}); |
| 64 |
}); |
| 65 |
|
| 66 |
describe('tasks', function() { |
| 67 |
|
| 68 |
it('returns an object of task name->functions', function(done) { |
| 69 |
var reg = new Registry(); |
| 70 |
reg.set('test1', noop); |
| 71 |
reg.set('test2', noop); |
| 72 |
expect(reg.tasks()).toEqual({ test1: noop, test2: noop }); |
| 73 |
done(); |
| 74 |
}); |
| 75 |
}); |
| 76 |
}); |