import classWithoutCallParentConstructor from 'class-without-call-parent-constructor';
describe(`describe`, () =>
{
class A
{
constructor(a: any, b: any)
{
console.log("A.constructor");
throw new Error('should not call A.constructor')
a;
b;
}
parentMethod()
{
console.log("A.parentMethod()");
return "A.parentMethod()"
}
}
test(`@ts-expect-error`, () =>
{
class B extends A
{
// @ts-expect-error
constructor()
{
}
}
// @ts-ignore
expect(() => new A).toThrowError();
expect(() => new B).toThrowError();
});
test(`classWithoutCallParentConstructor`, () =>
{
class B extends classWithoutCallParentConstructor(A)
{
constructor()
{
super();
}
childMethod()
{
console.log("B.childMethod()");
return "B.childMethod()"
}
}
expect(() => new B).not.toThrowError();
let actual = new B;
expect(actual).toHaveProperty('parentMethod')
expect(actual).toHaveProperty('childMethod')
expect(actual.parentMethod()).toStrictEqual('A.parentMethod()')
expect(actual.childMethod()).toStrictEqual('B.childMethod()')
});
test(`createNewTargetObject`, () =>
{
class B extends A
{
// @ts-ignore
constructor()
{
return createNewTargetObject(new.target)
}
childMethod()
{
console.log("B.childMethod()");
return "B.childMethod()"
}
}
expect(() => new B).not.toThrowError();
let actual = new B;
expect(actual).toHaveProperty('parentMethod')
expect(actual).toHaveProperty('childMethod')
expect(actual.parentMethod()).toStrictEqual('A.parentMethod()')
expect(actual.childMethod()).toStrictEqual('B.childMethod()')
});
})
Package detail
class-without-call-parent-constructor
create class skip call parent constructor
readme
changelog
Change Log
All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.
2.0.4 (2021-07-01)
Note: Version bump only for package class-without-call-parent-constructor
2.0.3 (2021-07-01)
Note: Version bump only for package class-without-call-parent-constructor
2.0.2 (2021-06-30)
🐛 Bug Fixes
- support static (65bad94)
2.0.1 (2021-06-28)
🛠 Build System
- update to es2019 (439e4c6)
⚙️ Continuous Integration
- add ci:install (75115fc)
🔖 Miscellaneous
- . (6e785fa)
BREAKING CHANGE
- update to es2019
1.0.2 (2021-06-28)
♻️ Chores
- https://stackoverflow.com/a/61541378/4563339 (8a07e6a)
- update package.json (ae435ce)
🔖 Miscellaneous
- class-without-call-parent-constructor (c08a684)