-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
93 lines (78 loc) · 2.3 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*!
* minibase-is-registered <https://github.com/node-minibase/minibase-is-registered>
*
* Copyright (c) Charlike Mike Reagent <@tunnckoCore> (https://i.am.charlike.online)
* Released under the MIT license.
*/
/* jshint asi:true */
'use strict'
var test = require('mukla')
var isRegistered = require('./index')
var MiniBase = require('minibase').MiniBase
test('should have `.isRegistered` method', function (done) {
var app = new MiniBase()
app.use(isRegistered())
test.strictEqual(typeof app.isRegistered, 'function')
done()
})
test('should not call plugin twice if it is already registered', function (done) {
var app = new MiniBase()
var called = 0
function plugin () {
return function foo (self) {
if (self.isRegistered('foo')) return
called = called + 22
}
}
app.use(isRegistered())
app.use(plugin())
app.use(plugin())
test.strictEqual(called, 22)
done()
})
test('should use `app.registered` prop if it is object and already exist', function (done) {
var minibase = new MiniBase()
var count = 33
function fn (self) {
if (self.isRegistered('bar')) return
count = count + 11
}
minibase.registered = { bar: true }
minibase.use(isRegistered())
minibase.use(fn)
minibase.use(fn)
test.strictEqual(count, 33)
done()
})
test('should has `_pluginName` property containing last register plugin', function (done) {
var app = new MiniBase()
app.on('error', done)
app.use(isRegistered())
app.use(function plugin (self) {
if (self.isRegistered('base-foo')) return
self.first = 1
test.strictEqual(self._pluginName, 'base-foo')
})
test.strictEqual(app.first, 1)
test.strictEqual(app._pluginName, 'base-foo')
app.use(function plugin (self) {
test.strictEqual(self._pluginName, 'base-foo')
test.strictEqual(self.first, 1)
if (self.isRegistered('base-qux')) return
self.second = 2
test.strictEqual(self._pluginName, 'base-qux')
})
test.strictEqual(app.first, 1)
test.strictEqual(app.second, 2)
test.strictEqual(app._pluginName, 'base-qux')
done()
})
test('should isRegistered return false if not a string passed to it', function (done) {
var app = new MiniBase()
app.on('error', done)
app.use(isRegistered())
app.use(function (app) {
test.strictEqual(app.isRegistered(null), false)
done()
})
})