-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
64 lines (58 loc) · 1.44 KB
/
test.js
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
'use strict';
require('mocha');
var assert = require('assert');
var isValid = require('./');
var Base = require('base');
var base;
describe('is-valid-app', function() {
beforeEach(function() {
base = new Base();
});
it('should export a function', function() {
assert.equal(typeof isValid, 'function');
});
it('should return false if the instance is not valid', function() {
var count = 0;
function plugin(app) {
if (!isValid(app, 'foo')) return;
count++;
}
base.use(plugin);
base.use(plugin);
base.use(plugin);
base.use(plugin);
base.use(plugin);
assert.equal(count, 0);
});
it('should allow custom instance types', function() {
var collection = new Base({isCollection: true});
var view = new Base({isView: true});
var count = 0;
function plugin(app) {
if (!isValid(app, 'foo', ['view', 'collection'])) return;
count++;
}
view.use(plugin);
collection.use(plugin);
base.use(plugin);
base.use(plugin);
base.use(plugin);
base.use(plugin);
base.use(plugin);
assert.equal(count, 2);
});
it('should return false if a plugin is registered already', function() {
base.isApp = true;
var count = 0;
function plugin(app) {
if (!isValid(app, 'foo')) return;
count++;
}
base.use(plugin);
base.use(plugin);
base.use(plugin);
base.use(plugin);
base.use(plugin);
assert.equal(count, 1);
});
});