Skip to content

Commit 58453bb

Browse files
committed
Tighten up tests around decorator targets.
1 parent ffc1ed4 commit 58453bb

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed

test/index.js

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ describe('decorators', function(){
125125

126126
it('should allow returning a descriptor', function(){
127127
function dec(target, name, descriptor){
128+
target.decoratedProps = (target.decoratedProps || []).concat([name]);
129+
128130
let value = descriptor.value;
129131
return {
130132
enumerable: name.indexOf('enum') !== -1,
@@ -177,6 +179,19 @@ describe('decorators', function(){
177179
return 8;
178180
}
179181
}
182+
183+
expect(Example.prototype).to.have.ownProperty('decoratedProps');
184+
expect(Example.prototype.decoratedProps).to.eql([
185+
"enumconfwrite",
186+
"enumconf",
187+
"enumwrite",
188+
"enum",
189+
"confwrite",
190+
"conf",
191+
"write",
192+
"_",
193+
]);
194+
180195
const inst = new Example();
181196

182197
const descs = Object.getOwnPropertyDescriptors(Example.prototype);
@@ -223,6 +238,8 @@ describe('decorators', function(){
223238

224239
it('should allow mutating the original descriptor', function(){
225240
function dec(target, name, descriptor){
241+
target.decoratedProps = (target.decoratedProps || []).concat([name]);
242+
226243
let value = descriptor.value;
227244
Object.assign(descriptor, {
228245
enumerable: name.indexOf('enum') !== -1,
@@ -275,6 +292,19 @@ describe('decorators', function(){
275292
return 8;
276293
}
277294
}
295+
296+
expect(Example.prototype).to.have.ownProperty('decoratedProps');
297+
expect(Example.prototype.decoratedProps).to.eql([
298+
"enumconfwrite",
299+
"enumconf",
300+
"enumwrite",
301+
"enum",
302+
"confwrite",
303+
"conf",
304+
"write",
305+
"_",
306+
]);
307+
278308
const inst = new Example();
279309

280310
const descs = Object.getOwnPropertyDescriptors(Example.prototype);
@@ -349,6 +379,8 @@ describe('decorators', function(){
349379

350380
it('should allow returning a descriptor', function(){
351381
function dec(target, name, descriptor){
382+
target.decoratedProps = (target.decoratedProps || []).concat([name]);
383+
352384
let value = descriptor.value;
353385
return {
354386
enumerable: name.indexOf('enum') !== -1,
@@ -402,6 +434,18 @@ describe('decorators', function(){
402434
}
403435
}
404436

437+
expect(Example).to.have.ownProperty('decoratedProps');
438+
expect(Example.decoratedProps).to.eql([
439+
"enumconfwrite",
440+
"enumconf",
441+
"enumwrite",
442+
"enum",
443+
"confwrite",
444+
"conf",
445+
"write",
446+
"_",
447+
]);
448+
405449
const descs = Object.getOwnPropertyDescriptors(Example);
406450
expect(descs.enumconfwrite.enumerable).to.be.true;
407451
expect(descs.enumconfwrite.writable).to.be.true;
@@ -446,6 +490,8 @@ describe('decorators', function(){
446490

447491
it('should allow mutating the original descriptor', function(){
448492
function dec(target, name, descriptor){
493+
target.decoratedProps = (target.decoratedProps || []).concat([name]);
494+
449495
let value = descriptor.value;
450496
Object.assign(descriptor, {
451497
enumerable: name.indexOf('enum') !== -1,
@@ -499,6 +545,18 @@ describe('decorators', function(){
499545
}
500546
}
501547

548+
expect(Example).to.have.ownProperty('decoratedProps');
549+
expect(Example.decoratedProps).to.eql([
550+
"enumconfwrite",
551+
"enumconf",
552+
"enumwrite",
553+
"enum",
554+
"confwrite",
555+
"conf",
556+
"write",
557+
"_",
558+
]);
559+
502560
const descs = Object.getOwnPropertyDescriptors(Example);
503561
expect(descs.enumconfwrite.enumerable).to.be.true;
504562
expect(descs.enumconfwrite.writable).to.be.true;
@@ -559,6 +617,8 @@ describe('decorators', function(){
559617

560618
it('should allow returning a descriptor', function(){
561619
function dec(target, name, descriptor){
620+
target.decoratedProps = (target.decoratedProps || []).concat([name]);
621+
562622
let initializer = descriptor.initializer;
563623
return {
564624
enumerable: name.indexOf('enum') !== -1,
@@ -597,6 +657,18 @@ describe('decorators', function(){
597657
}
598658
const inst = new Example();
599659

660+
expect(Example.prototype).to.have.ownProperty('decoratedProps');
661+
expect(inst.decoratedProps).to.eql([
662+
"enumconfwrite",
663+
"enumconf",
664+
"enumwrite",
665+
"enum",
666+
"confwrite",
667+
"conf",
668+
"write",
669+
"_",
670+
]);
671+
600672
const descs = Object.getOwnPropertyDescriptors(inst);
601673
expect(descs.enumconfwrite.enumerable).to.be.true;
602674
expect(descs.enumconfwrite.writable).to.be.true;
@@ -643,6 +715,8 @@ describe('decorators', function(){
643715

644716
it('should allow mutating the original descriptor', function(){
645717
function dec(target, name, descriptor){
718+
target.decoratedProps = (target.decoratedProps || []).concat([name]);
719+
646720
let initializer = descriptor.initializer;
647721
Object.assign(descriptor, {
648722
enumerable: name.indexOf('enum') !== -1,
@@ -681,6 +755,18 @@ describe('decorators', function(){
681755
}
682756
const inst = new Example();
683757

758+
expect(Example.prototype).to.have.ownProperty('decoratedProps');
759+
expect(inst.decoratedProps).to.eql([
760+
"enumconfwrite",
761+
"enumconf",
762+
"enumwrite",
763+
"enum",
764+
"confwrite",
765+
"conf",
766+
"write",
767+
"_",
768+
]);
769+
684770
const descs = Object.getOwnPropertyDescriptors(inst);
685771
expect(descs.enumconfwrite.enumerable).to.be.true;
686772
expect(descs.enumconfwrite.writable).to.be.true;
@@ -816,6 +902,8 @@ describe('decorators', function(){
816902

817903
it('should allow returning a descriptor', function(){
818904
function dec(target, name, descriptor){
905+
target.decoratedProps = (target.decoratedProps || []).concat([name]);
906+
819907
let value = descriptor.value;
820908
return {
821909
enumerable: name.indexOf('enum') !== -1,
@@ -869,6 +957,18 @@ describe('decorators', function(){
869957
},
870958
}
871959

960+
expect(inst).to.have.ownProperty('decoratedProps');
961+
expect(inst.decoratedProps).to.eql([
962+
"enumconfwrite",
963+
"enumconf",
964+
"enumwrite",
965+
"enum",
966+
"confwrite",
967+
"conf",
968+
"write",
969+
"_",
970+
]);
971+
872972
const descs = Object.getOwnPropertyDescriptors(inst);
873973
expect(descs.enumconfwrite.enumerable).to.be.true;
874974
expect(descs.enumconfwrite.writable).to.be.true;
@@ -913,6 +1013,8 @@ describe('decorators', function(){
9131013

9141014
it('should allow mutating the original descriptor', function(){
9151015
function dec(target, name, descriptor){
1016+
target.decoratedProps = (target.decoratedProps || []).concat([name]);
1017+
9161018
let value = descriptor.value;
9171019
Object.assign(descriptor, {
9181020
enumerable: name.indexOf('enum') !== -1,
@@ -966,6 +1068,18 @@ describe('decorators', function(){
9661068
},
9671069
}
9681070

1071+
expect(inst).to.have.ownProperty('decoratedProps');
1072+
expect(inst.decoratedProps).to.eql([
1073+
"enumconfwrite",
1074+
"enumconf",
1075+
"enumwrite",
1076+
"enum",
1077+
"confwrite",
1078+
"conf",
1079+
"write",
1080+
"_",
1081+
]);
1082+
9691083
const descs = Object.getOwnPropertyDescriptors(inst);
9701084
expect(descs.enumconfwrite.enumerable).to.be.true;
9711085
expect(descs.enumconfwrite.writable).to.be.true;
@@ -1034,6 +1148,8 @@ describe('decorators', function(){
10341148

10351149
it('should allow returning a descriptor', function(){
10361150
function dec(target, name, descriptor){
1151+
target.decoratedProps = (target.decoratedProps || []).concat([name]);
1152+
10371153
let initializer = descriptor.initializer;
10381154
return {
10391155
enumerable: name.indexOf('enum') !== -1,
@@ -1071,6 +1187,18 @@ describe('decorators', function(){
10711187
_: 8,
10721188
};
10731189

1190+
expect(inst).to.have.ownProperty('decoratedProps');
1191+
expect(inst.decoratedProps).to.eql([
1192+
"enumconfwrite",
1193+
"enumconf",
1194+
"enumwrite",
1195+
"enum",
1196+
"confwrite",
1197+
"conf",
1198+
"write",
1199+
"_",
1200+
]);
1201+
10741202
const descs = Object.getOwnPropertyDescriptors(inst);
10751203
expect(descs.enumconfwrite.enumerable).to.be.true;
10761204
expect(descs.enumconfwrite.writable).to.be.true;
@@ -1115,6 +1243,8 @@ describe('decorators', function(){
11151243

11161244
it('should allow mutating the original descriptor', function(){
11171245
function dec(target, name, descriptor){
1246+
target.decoratedProps = (target.decoratedProps || []).concat([name]);
1247+
11181248
let initializer = descriptor.initializer;
11191249
Object.assign(descriptor, {
11201250
enumerable: name.indexOf('enum') !== -1,
@@ -1152,6 +1282,18 @@ describe('decorators', function(){
11521282
_: 8,
11531283
};
11541284

1285+
expect(inst).to.have.ownProperty('decoratedProps');
1286+
expect(inst.decoratedProps).to.eql([
1287+
"enumconfwrite",
1288+
"enumconf",
1289+
"enumwrite",
1290+
"enum",
1291+
"confwrite",
1292+
"conf",
1293+
"write",
1294+
"_",
1295+
]);
1296+
11551297
const descs = Object.getOwnPropertyDescriptors(inst);
11561298
expect(descs.enumconfwrite.enumerable).to.be.true;
11571299
expect(descs.enumconfwrite.writable).to.be.true;

0 commit comments

Comments
 (0)