diff --git a/README.md b/README.md index e9f78d6..9a432d0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # ts-stubber ![ts-stubber](https://github.com/ShellyDCMS/ts-stubber/actions/workflows/npm-publish.yml/badge.svg) -![NPM](https://img.shields.io/npm/v/ts-stubber) [![NPM](https://img.shields.io/npm/v/ts-stubber)](https://www.npmjs.com/package/ts-stubber) ![MIT](https://camo.githubusercontent.com/a4426cbe5c21edb002526331c7a8fbfa089e84a550567b02a0d829a98b136ad0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667) ![typescript](https://camo.githubusercontent.com/017786f7ebc845ae38c14f3bc28dc6162e756f33ea8549fd4f9071c405edb5de/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2533432532462533452d547970655363726970742d2532333030373463312e737667) @@ -20,11 +19,11 @@ Thus, enabling both avoiding side effects that may occur while class constructor ## Installation -`npm i -D @ts-stubber` +`npm i -D ts-stubber` or -`yarn add -D @ts-stubber` +`yarn add -D ts-stubber` ## Usage diff --git a/package.json b/package.json index f3ece90..6e72e91 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ts-stubber", "description": "Lazy Stubbing a TypeScript Class or Interface with any Mocking Framework for testing in Isolation", - "version": "1.0.17", + "version": "1.0.18", "author": "Shelly Goldblit", "private": false, "license": "MIT", diff --git a/src/stub-builder.cy.ts b/src/stub-builder.cy.ts index 695b476..f364334 100644 --- a/src/stub-builder.cy.ts +++ b/src/stub-builder.cy.ts @@ -181,6 +181,30 @@ describe("Cypress stub builder tests with Sinon Stubs", () => { expect(await mockMyInheritedClass.asynFunc(input)).to.eq(returnValue); }); + it("async function should return value according to param", async () => { + const mockMyClass = stubbedInstanceCreator.createStubbedInstance(); + mockMyClass.asynFunc.withArgs(1).resolves(101); + expect(await mockMyClass.asynFunc(1)).to.eq(101); + }); + + it("property async should return value according to param", async () => { + const mockMyClass = stubbedInstanceCreator.createStubbedInstance(); + mockMyClass.asyncPropertyFunc.withArgs(1).returns(Promise.resolve(101)); + expect(await mockMyClass.asyncPropertyFunc(1)).to.eq(101); + }); + + it("func should return value according to param", () => { + const mockMyClass = stubbedInstanceCreator.createStubbedInstance(); + mockMyClass.func.withArgs(0, "whatever").returns(99); + expect(mockMyClass.func(0, "whatever")).to.eq(99); + }); + + it("property func should return value according to param", () => { + const mockMyClass = stubbedInstanceCreator.createStubbedInstance(); + mockMyClass.propertyFunc.withArgs(3).returns(55); + expect(mockMyClass.propertyFunc(3)).to.eq(55); + }); + it("should stub async function using overrides", async () => { const stub = sinon.stub().returns(Promise.resolve(returnValue)); const mockMyInheritedClass = diff --git a/src/stub-builder.ts b/src/stub-builder.ts index a1ba8b7..9232b8f 100644 --- a/src/stub-builder.ts +++ b/src/stub-builder.ts @@ -66,6 +66,7 @@ export const StubbedInstanceCreator = ( target: Record, prop: string ) => { + debugger; if (!(prop in target)) { target[prop] = createStub(prop); }