Repository navigation
Expand file tree
/
Copy pathcontrol.test.js
More file actions
100 lines (72 loc) · 2.7 KB
/
Copy pathcontrol.test.js
File metadata and controls
100 lines (72 loc) · 2.7 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
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
'use strict';
const _ = require('lodash'),
filename = __filename.split('/').pop().split('.').shift(),
lib = require('./' + filename),
expect = require('chai').expect,
sinon = require('sinon');
describe(_.startCase(filename), function () {
let sandbox;
beforeEach(function () {
sandbox = sinon.sandbox.create();
sandbox.stub(console, 'warn');
sandbox.stub(console, 'log');
});
afterEach(function () {
sandbox.restore();
});
describe('memoize', function () {
let memLeak;
const fn = lib[this.title];
beforeEach(function () {
memLeak = lib.getMemoryLeakThreshold();
});
afterEach(function () {
lib.setMemoryLeakThreshold(memLeak);
});
it('memoizes', function () {
let resultFn, target = function () { return 'd'; };
resultFn = fn(target);
resultFn('a', 'b', 'c');
expect(_.get(resultFn, 'cache.__data__.string.__data__')).to.deep.equal({a: 'd'});
});
it('warns when over the limit', function () {
let resultFn, target = function namedFn() { return 'd'; };
lib.setMemoryLeakThreshold(2);
resultFn = fn(target);
resultFn('a');
resultFn('b');
resultFn('c');
sinon.assert.calledOnce(console.log);
});
});
describe('defineReadOnly', function () {
const fn = lib[this.title];
it('defines a property that is read-only', function () {
expect(fn({})).to.deep.equal({ writable: false, enumerable: false, configurable: false});
});
it('defines a property that is read-only with a getter', function () {
const getter = _.noop;
expect(fn({get: getter})).to.deep.equal({ enumerable: false, configurable: false, get: getter});
});
it('defines a property that is read-only with a getter and setter, but only the getter works', function () {
const getter = _.noop,
setter = _.noop;
expect(fn({get: getter, set: setter})).to.deep.equal({ enumerable: false, configurable: false, get: getter});
});
});
describe('defineWritable', function () {
const fn = lib[this.title];
it('defines a property that is writable', function () {
expect(fn({})).to.deep.equal({writable: true, enumerable: false, configurable: false});
});
it('defines a property that is writable with a getter', function () {
const getter = _.noop;
expect(fn({get: getter})).to.deep.equal({enumerable: false, configurable: false, get: getter});
});
it('defines a property that is writable with a getter and setter', function () {
const getter = _.noop,
setter = _.noop;
expect(fn({get: getter, set: setter})).to.deep.equal({enumerable: false, configurable: false, get: getter, set: setter});
});
});
});