app-test.js
1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* app-test.js: Tests for core App methods and configuration.
*
* (C) 2011, Nodejitsu Inc.
* MIT LICENSE
*
*/
var events = require('eventemitter2'),
vows = require('vows'),
assert = require('../helpers/assert'),
broadway = require('../../lib/broadway');
vows.describe('broadway/app').addBatch({
"An instance of broadway.App": {
topic: new broadway.App(),
"should have the correct properties and methods": function (app) {
//
// Instance
//
assert.isObject(app);
assert.instanceOf(app, events.EventEmitter2);
assert.instanceOf(app, broadway.App);
//
// Properties
//
assert.isObject(app.plugins);
assert.isObject(app.initializers);
assert.isFalse(!!app.initialized);
//
// Methods
//
assert.isFunction(app.init);
assert.isFunction(app.use);
assert.isFunction(app.remove);
assert.isFunction(app.inspect);
},
"the init() method": {
topic: function (app) {
this.app = app;
app.init(this.callback);
},
"should correctly setup the application state": function () {
assert.isTrue(this.app.initialized);
assert.isTrue(this.app.initializers['log']);
assert.plugins.has.config(this.app);
assert.plugins.has.log(this.app);
}
},
"the detach() method": {
topic: function (app) {
app.use({
name: "foo",
attach: function () {
this.attached = true;
},
detach: function () {
this.detached = true;
}
});
app.remove("foo");
return app;
},
"should correctly remove a plugin": function (app) {
assert.isTrue(app.detached);
assert.equal(undefined, app.plugins["foo"]);
}
}
}
}).export(module);