-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
106 lines (95 loc) · 3.13 KB
/
index.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
/**
* Tests nepp.
*/
var should = require('should'),
nepp = require(process.env.NEPP_COV ?'../lib-cov/' : '../lib/');
describe('nepp', function() {
describe('#', function() {
it('should nepp all _ properties of object', function(done) {
var A = function() {
this._foo = 'bar';
nepp(this);
};
var a = new A();
a._foo.should.equal('bar');
for (var i in a) {
if (i == '_foo') {
done('a._foo must not be enumerable');
return
}
}
done();
});
it('should nepp all TESTNAMESPACE properties', function(done) {
var A = function() {
this.TESTNAMESPACEfoo = 'bar';
nepp(this, 'TESTNAMESPACE');
};
var a = new A();
a.TESTNAMESPACEfoo.should.equal('bar');
for (var i in a) {
if (i == 'TESTNAMESPACEfoo') {
done('a.TESTNAMESPACEfoo must not be enumerable');
return;
}
}
done();
});
});
describe('#createGS', function() {
it('should throw if neither getter nor setter ist set', function() {
(function() {
nepp.createGS({}, 'foo');
}).should.throw();
});
it('should define an enumerable getter', function(done) {
var A = function() { this._foo = 'bar'; nepp(this)};
nepp.createGS(A.prototype, 'foo', function() { return this._foo });
var a = new A();
a.foo.should.equal(a._foo);
for (var i in a) {
if (i == 'foo') {
done();
return;
}
}
done('getter is not enumerable!');
});
it('should define an enumerable setter', function(done) {
var A = function() { this._foo = 'bar'; nepp(this) };
nepp.createGS(
A.prototype, 'foo', undefined, function(v) { this._foo = v }
);
var a = new A();
should.equal(a.foo, undefined);
a.foo = 'baz';
a._foo.should.equal('baz');
for (var i in a) {
if (i == 'foo') {
done();
return;
}
}
done('setter is not enumerable!');
});
it('should define an enumerable getter and setter', function(done) {
var A = function() { this._foo = 'bar'; nepp(this) };
nepp.createGS(
A.prototype, 'foo',
function() { return this._foo },
function(v) { this._foo = v }
);
var a = new A();
should.equal(a.foo, 'bar');
a.foo = 'baz';
a._foo.should.equal('baz');
for (var i in a) {
if (i == 'foo') {
done();
return;
}
}
done('getter/setter is not enumerable!');
});
});
});