-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathcustom-property.js
111 lines (93 loc) · 2.85 KB
/
custom-property.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
/*!
* cache-base <https://github.com/jonschlinkert/cache-base>
*
* Copyright (c) 2014-2018, Jon Schlinkert.
* Licensed under the MIT License.
*/
'use strict';
require('mocha');
const assert = require('assert');
const Cache = require('../');
let app, cache;
describe('custom property', function() {
beforeEach(function() {
app = new Cache('data');
});
describe('constructor:', function() {
it('should create an instance of Cache', function() {
assert(app instanceof Cache);
});
it('should set ', function() {
app = new Cache('data', { one: 1, two: 2 });
assert.equal(app.data.one, 1);
assert.equal(app.data.two, 2);
});
});
describe('get/set:', function() {
describe('set() - add:', function() {
it('should set a new property with the given value', function() {
app.set('one', 1);
assert.equal(app.get('one'), 1);
assert.equal(app.data.one, 1);
});
});
describe('set() - update:', function() {
it('should update an existing property with the given value', function() {
app.set('one', 2);
assert.equal(app.get('one'), 2);
assert.equal(app.data.one, 2);
});
it('should get the given property', function() {
app.set('a', 'b');
assert.equal(app.get('a'), 'b');
assert.equal(app.data.a, 'b');
});
});
});
describe('.set()', function() {
it('should set a value', function() {
app.set('a', 'b');
assert.equal(app.get('a'), 'b');
assert.equal(app.data.a, 'b');
});
it('should set properties on the `data` object', function() {
app.set('a', 'b');
assert.equal(app.data.a, 'b');
});
it('should allow an object to be set directly', function() {
app.set({x: 'y'});
assert.equal(app.data.x, 'y');
assert.equal(app.get('x'), 'y');
});
it('should set nested properties on the `data` object', function() {
app.set('c', {d: 'e'});
assert.equal(app.get('c').d, 'e');
});
it('should return the instance', function() {
assert.equal(app.set('a', 'b'), app);
});
it('should be chainable', function() {
app
.set('aa', 'bb')
.set('bb', 'cc')
.set('cc', 'dd');
assert.equal(app.get('aa'), 'bb');
assert.equal(app.get('bb'), 'cc');
assert.equal(app.get('cc'), 'dd');
assert.equal(app.data.aa, 'bb');
assert.equal(app.data.bb, 'cc');
assert.equal(app.data.cc, 'dd');
});
it('should return undefined when not set', function() {
assert.equal(app.set('sfsfsdfs', undefined), app);
});
});
describe('.get()', function() {
it('should otherwise return the value', function() {
app.set('a', 'b');
assert.equal(app.get('a'), 'b');
assert.equal(app.data.a, 'b');
assert.equal(app.get('zllzzl'), undefined);
});
});
});