New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

class-without-call-parent-constructor

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

class-without-call-parent-constructor

create class skip call parent constructor

latest
Source
npmnpm
Version
2.0.5
Version published
Maintainers
1
Created
Source
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()')

	});

})

Keywords

create

FAQs

Package last updated on 30 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts