-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
206 lines (173 loc) · 5.36 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
'use strict';
require('mocha');
var Base = require('base');
var assert = require('assert');
var plugins = require('base-plugins');
var options = require('./');
var app;
Base.use(function() {
this.isApp = true;
});
describe('option', function() {
beforeEach(function() {
app = new Base();
app.use(options());
});
describe('method', function() {
it('should add the option method to the `app` instance:', function() {
assert.equal(typeof app.option, 'function');
});
it('should not add the option method to the `Base` prototype:', function() {
assert.notEqual(typeof Base.prototype.option, 'function');
});
});
describe('plugin', function() {
it('should add options passed to the plugin', function() {
app = new Base();
app.use(options({z: 'y'}));
assert.equal(app.options.z, 'y');
});
it('should pass the plugin to "run" when the `plugins` plugin is used', function() {
app = new Base();
app.use(plugins());
app.use(options());
assert.equal(app.fns.length, 1);
});
it('should pass the plugin to "run" when {run:false} is defined', function() {
app.use(plugins());
app.use(options({run: false}));
assert.equal(app.fns.length, 0);
});
it('should not overwrite existing options', function() {
app.options.foo = 'bar';
app.use(options());
app.option('a', 'b');
assert.equal(app.options.foo, 'bar');
assert.equal(app.options.a, 'b');
});
it('should set options as key-value pairs', function() {
app.option('a', 'b');
assert.equal(app.options.a, 'b');
});
it('should set an object', function() {
app.option({c: 'd'});
var c = app.option('c');
assert.equal(c, 'd');
});
it('should set multiple values', function() {
app.option({a: 'b'});
app.option({c: 'd'});
assert.equal(app.options.a, 'b');
assert.equal(app.options.c, 'd');
});
it('should set multiple values using key-value', function() {
app.option('a', 'b');
app.option('c', 'd');
assert.equal(app.options.a, 'b');
assert.equal(app.options.c, 'd');
});
it('should set multiple nested values using dot-notation', function() {
app.option('a.b', 'c');
app.option('a.c', 'd');
assert.equal(app.options.a.b, 'c');
assert.equal(app.options.a.c, 'd');
});
it('should get options', function() {
app.option('a', 'b');
var a = app.option('a');
assert.equal(a, 'b');
});
it('should return true if an option exists', function() {
app.option('a', 'b');
assert(app.hasOption('a'));
});
it('should enable an option', function() {
assert(!app.options.a);
app.enable('a');
assert(app.options.a);
});
it('should disable an option', function() {
app.enable('a');
assert(app.options.a);
app.disable('a');
assert(!app.options.a);
});
it('should set nested options', function() {
app.option('a.b.c', 'd');
assert.deepEqual(app.options.a, {b: {c: 'd'}});
});
it('should get nested options', function() {
app.option('a.b.c', 'd');
assert.deepEqual(app.option('a'), {b: {c: 'd'}});
assert.deepEqual(app.option('a.b'), {c: 'd'});
assert.deepEqual(app.option('a.b.c'), 'd');
});
});
describe('option.set', function() {
beforeEach(function() {
app = new Base();
app.use(options());
});
it('should set a key-value pair on app.options', function() {
app.option.set('a', 'b');
app.option.set('c', 'd');
assert.equal(app.options.a, 'b');
assert.equal(app.options.c, 'd');
});
});
describe('option.get', function() {
beforeEach(function() {
app = new Base();
app.use(options());
});
it('should get a key-value pair from app.options', function() {
app.option.set('a', 'b');
app.option.set('c', 'd');
assert.equal(app.option.get('a'), 'b');
assert.equal(app.option.get('c'), 'd');
});
});
describe('option.create', function() {
beforeEach(function() {
app = new Base();
app.use(options());
});
it('should clone options', function() {
app.option({a: 'b', c: 'd'});
var opts = app.option.create();
app.option({e: 'f'});
assert.equal(opts.a, 'b');
assert.equal(opts.c, 'd');
assert.equal(typeof opts.e, 'undefined');
});
it('should expose a set method', function() {
app.option({a: 'b', c: 'd'});
var opts = app.option.create();
opts.set('e', 'f');
opts.set('g', 'h');
assert.equal(opts.a, 'b');
assert.equal(opts.c, 'd');
assert.equal(opts.e, 'f');
assert.equal(opts.g, 'h');
});
it('should expose a get method', function() {
app.option({a: 'b', c: 'd'});
var opts = app.option.create();
opts.set('e', 'f');
opts.set('g', 'h');
assert.equal(opts.get('a'), 'b');
assert.equal(opts.get('c'), 'd');
assert.equal(opts.get('e'), 'f');
assert.equal(opts.get('g'), 'h');
});
it('should expose a merge method', function() {
app.option({a: 'b', c: 'd'});
var opts = app.option.create();
opts.merge({e: 'f'}, {g: 'h'});
assert.equal(opts.a, 'b');
assert.equal(opts.c, 'd');
assert.equal(opts.e, 'f');
assert.equal(opts.g, 'h');
});
});
});