Skip to content

Commit daecc35

Browse files
committed
chore(cleanup): slight bit of cleanup
1 parent 258ba4b commit daecc35

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

src/utils/wrapConstructor.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { expect } from 'chai';
2+
3+
import { wrapConstructor } from './wrapConstructor';
4+
5+
describe('when wrapping a constructor', () => {
6+
it('should retain the original name of the constructor', () => {
7+
class Test {}
8+
9+
const Wrapper = wrapConstructor(Test, function Blorg() {});
10+
11+
expect(Wrapper.name).to.equal('Test');
12+
});
13+
});

src/utils/wrapConstructor.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ export function wrapConstructor(Ctor: Function, wrapper: (Ctor: Function, ...arg
2222
}
2323

2424
ConstructorWrapper.prototype = Ctor.prototype;
25-
Object.defineProperty(ConstructorWrapper, 'name', { writable: true });
26-
(ConstructorWrapper as any).name = Ctor.name;
25+
Object.defineProperty(ConstructorWrapper, 'name', {
26+
// These values should coincide with the default descriptor values for `name`.
27+
configurable: true,
28+
enumerable: false,
29+
value: Ctor.name,
30+
writable: false
31+
});
2732

2833
return assignAll(ConstructorWrapper, Ctor, PROPERTY_EXCLUDES);
2934
}

0 commit comments

Comments
 (0)