1.0.0 • Published 1 year ago
@shellygo/ts-stubber v1.0.0
ts-stubber
A generic stubbed instance creator to lazy stub any interface/class, without calling class's constructor.
Markdown Documentation
HTML Documentation
Usage
This library provides an API to create a stubbed instance of a class or interface, including property functions, allowing overrides and excluded methods.
class MyClass {
constructor(input: number) {
throw new Error("Should not be called");
}
func(input: number, text: string) {
console.log(text);
return input;
}
property: number = 3;
optionalProperty?: number;
get getter(): number {
return this.property;
}
set setter(value: number) {
throw new Error("Should not be called");
}
}
const stubbedInstanceCreator = StubbedInstanceCreator<MyClass, SinonStub>(() =>
sinon.stub()
);
const mockMyClass = StubbedInstanceCreator<MyClass, SinonStub>(() =>
sinon.stub()
).createStubbedInstance();
npm i -D @shellygo/ts-stubber
or
yarn add -D @shellygo/ts-stubber
Developing
- Set up the repo -
yarn
- Build the project -
npm run build
- Running tests -
npm run cy:run
1.0.0
1 year ago