From 756bea6bde8ec5e85d5d1c33cbd9e208954a5c58 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 1 Nov 2023 15:44:19 +0000 Subject: [PATCH] deps(dev): bump aegir from 37.12.1 to 41.1.4 (#9) Bumps [aegir](https://github.com/ipfs/aegir) from 37.12.1 to 41.1.4. - [Release notes](https://github.com/ipfs/aegir/releases) - [Changelog](https://github.com/ipfs/aegir/blob/master/CHANGELOG.md) - [Commits](https://github.com/ipfs/aegir/compare/v37.12.1...v41.1.4) --- updated-dependencies: - dependency-name: aegir dependency-type: direct:development update-type: version-update:semver-major ... --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: achingbrain --- .github/workflows/js-test-and-release.yml | 154 ++----------- .github/workflows/semantic-pull-request.yml | 12 ++ .github/workflows/stale.yml | 13 ++ .gitignore | 14 +- README.md | 227 +++++++------------- package.json | 12 +- src/index.ts | 152 ++++++++++++- test/index.spec.ts | 107 +++++---- typedoc.json | 5 + 9 files changed, 338 insertions(+), 358 deletions(-) create mode 100644 .github/workflows/semantic-pull-request.yml create mode 100644 .github/workflows/stale.yml create mode 100644 typedoc.json diff --git a/.github/workflows/js-test-and-release.yml b/.github/workflows/js-test-and-release.yml index d155996..2c7a14b 100644 --- a/.github/workflows/js-test-and-release.yml +++ b/.github/workflows/js-test-and-release.yml @@ -1,145 +1,25 @@ name: test & maybe release + on: push: branches: - - master # with #262 - ${{{ github.default_branch }}} + - master pull_request: - branches: - - master # with #262 - ${{{ github.default_branch }}} - -jobs: - - check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: lts/* - - uses: ipfs/aegir/actions/cache-node-modules@master - - run: npm run --if-present lint - - run: npm run --if-present dep-check - - test-node: - needs: check - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [windows-latest, ubuntu-latest, macos-latest] - node: [16] - fail-fast: true - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node }} - - uses: ipfs/aegir/actions/cache-node-modules@master - - run: npm run --if-present test:node - - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 - with: - flags: node + workflow_dispatch: - test-chrome: - needs: check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: lts/* - - uses: ipfs/aegir/actions/cache-node-modules@master - - run: npm run --if-present test:chrome - - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 - with: - flags: chrome +permissions: + contents: write + packages: write - test-chrome-webworker: - needs: check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: lts/* - - uses: ipfs/aegir/actions/cache-node-modules@master - - run: npm run --if-present test:chrome-webworker - - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 - with: - flags: chrome-webworker +concurrency: + group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event_name == 'push' && github.sha || github.ref }} + cancel-in-progress: true - test-firefox: - needs: check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: lts/* - - uses: ipfs/aegir/actions/cache-node-modules@master - - run: npm run --if-present test:firefox - - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 - with: - flags: firefox - - test-firefox-webworker: - needs: check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: lts/* - - uses: ipfs/aegir/actions/cache-node-modules@master - - run: npm run --if-present test:firefox-webworker - - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 - with: - flags: firefox-webworker - - test-electron-main: - needs: check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: lts/* - - uses: ipfs/aegir/actions/cache-node-modules@master - - run: npx xvfb-maybe npm run --if-present test:electron-main - - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 - with: - flags: electron-main - - test-electron-renderer: - needs: check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: lts/* - - uses: ipfs/aegir/actions/cache-node-modules@master - - run: npx xvfb-maybe npm run --if-present test:electron-renderer - - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 - with: - flags: electron-renderer - - release: - needs: [test-node, test-chrome, test-chrome-webworker, test-firefox, test-firefox-webworker, test-electron-main, test-electron-renderer] - runs-on: ubuntu-latest - if: github.event_name == 'push' && github.ref == 'refs/heads/master' # with #262 - 'refs/heads/${{{ github.default_branch }}}' - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - uses: actions/setup-node@v3 - with: - node-version: lts/* - - uses: ipfs/aegir/actions/cache-node-modules@master - - uses: ipfs/aegir/actions/docker-login@master - with: - docker-token: ${{ secrets.DOCKER_TOKEN }} - docker-username: ${{ secrets.DOCKER_USERNAME }} - - run: npm run --if-present release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} +jobs: + js-test-and-release: + uses: pl-strflt/uci/.github/workflows/js-test-and-release.yml@v0.0 + secrets: + DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }} + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + UCI_GITHUB_TOKEN: ${{ secrets.UCI_GITHUB_TOKEN }} diff --git a/.github/workflows/semantic-pull-request.yml b/.github/workflows/semantic-pull-request.yml new file mode 100644 index 0000000..bd00f09 --- /dev/null +++ b/.github/workflows/semantic-pull-request.yml @@ -0,0 +1,12 @@ +name: Semantic PR + +on: + pull_request_target: + types: + - opened + - edited + - synchronize + +jobs: + main: + uses: pl-strflt/.github/.github/workflows/reusable-semantic-pull-request.yml@v0.3 diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 0000000..16d65d7 --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,13 @@ +name: Close and mark stale issue + +on: + schedule: + - cron: '0 0 * * *' + +permissions: + issues: write + pull-requests: write + +jobs: + stale: + uses: pl-strflt/.github/.github/workflows/reusable-stale-issue.yml@v0.3 diff --git a/.gitignore b/.gitignore index b6092da..7ad9e67 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,9 @@ -.vscode -.idea -dist/ -node_modules/ -.DS_Store +node_modules +build +dist +.docs +.coverage +node_modules package-lock.json -*.log +yarn.lock +.vscode diff --git a/README.md b/README.md index db8c31f..fa0c8de 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,9 @@ -# sinon-ts - [![codecov](https://img.shields.io/codecov/c/github/achingbrain/sinon-ts.svg?style=flat-square)](https://codecov.io/gh/achingbrain/sinon-ts) -[![CI](https://img.shields.io/github/workflow/status/achingbrain/sinon-ts/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/achingbrain/sinon-ts/actions/workflows/js-test-and-release.yml) +[![CI](https://img.shields.io/github/actions/workflow/status/achingbrain/sinon-ts/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/achingbrain/sinon-ts/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) > sinon library extension to stub whole object and interfaces -## Table of contents - -- [Install](#install) -- [What is this](#what-is-this) -- [Prerequisites](#prerequisites) -- [Object stubs example](#object-stubs-example) -- [Interface stubs example](#interface-stubs-example) -- [Object constructor stub example](#object-constructor-stub-example) -- [Sinon methods](#sinon-methods) -- [Packages](#packages) - - [Dependencies:](#dependencies) - - [Dev Dependencies:](#dev-dependencies) -- [Tests](#tests) -- [License](#license) -- [Contribute](#contribute) - -## Install - -```console -$ npm i sinon-ts -``` - -## What is this +# About A fork of [ts-sinon](https://www.npmjs.com/package/ts-sinon) that lets you BYO sinon. Can probably be retired if [ttarnowski/ts-sinon#255](https://github.com/ttarnowski/ts-sinon/pull/255) is ever merged. @@ -40,176 +16,141 @@ A fork of [ts-sinon](https://www.npmjs.com/package/ts-sinon) that lets you BYO s 1. You have a version of Node.js >= [v8.4.0](https://nodejs.org/en/download/) 2. You have installed [Typescript](https://www.typescriptlang.org/index.html#download-links) -## Object stubs example - -Importing stubObject function: +## Example -- import single function: +Stub all object methods ```javascript -import { stubObject } from "ts-sinon"; -``` - -- import as part of sinon singleton: +import { stubObject } from 'ts-sinon' -```typescript -import * as sinon from "ts-sinon"; - -const stubObject = sinon.stubObject; -``` - -Stub all object methods: - -```typescript class Test { - method() { return "original" } + method() { return 'original' } } -const test = new Test(); -const testStub = stubObject(test); +const test = new Test() +const testStub = stubObject(test) -testStub.method.returns("stubbed"); +testStub.method.returns('stubbed') -expect(testStub.method()).to.equal("stubbed"); +expect(testStub.method()).to.equal('stubbed') ``` -Partial stub: +## Example + +Partial stub ```typescript class Test { - public someProp: string = "test"; - methodA() { return "A: original" } - methodB() { return "B: original" } + public someProp: string = 'test' + methodA() { return 'A: original' } + methodB() { return 'B: original' } } -const test = new Test(); -// second argument must be existing class method name, in this case only "methodA" or "methodB" are accepted. -const testStub = stubObject(test, ["methodA"]); +const test = new Test() +// second argument must be existing class method name, in this case only 'methodA' or 'methodB' are accepted. +const testStub = stubObject(test, ['methodA']) -expect(testStub.methodA()).to.be.undefined; -expect(testStub.methodB()).to.equal("B: original"); +expect(testStub.methodA()).to.be.undefined +expect(testStub.methodB()).to.equal('B: original') ``` -Stub with predefined return values (type-safe): +## Example + +Stub with predefined return values (type-safe) ```typescript class Test { - method() { return "original" } + method() { return 'original' } } -const test = new Test(); -const testStub = stubObject(test, { method: "stubbed" }); +const test = new Test() +const testStub = stubObject(test, { method: 'stubbed' }) -expect(testStub.method()).to.equal("stubbed"); +expect(testStub.method()).to.equal('stubbed') ``` -## Interface stubs example - -Importing stubInterface function: +## Example -- import single function: +Interface stub (stub all methods) ```typescript -import { stubInterface } from "ts-sinon"; -``` - -- import as part of sinon singleton: - -```typescript -import * as sinon from "ts-sinon"; - -const stubInterface = sinon.stubInterface; -``` - -Interface stub (stub all methods): +import { stubInterface } from 'ts-sinon' -```typescript interface Test { - method(): string; + method(): string } -const testStub = stubInterface(); +const testStub = stubInterface() -expect(testStub.method()).to.be.undefined; +expect(testStub.method()).to.be.undefined -testStub.method.returns("stubbed"); +testStub.method.returns('stubbed') -expect(testStub.method()).to.equal("stubbed"); +expect(testStub.method()).to.equal('stubbed') ``` -Interface stub with predefined return values (type-safe): +## Example + +Interface stub with predefined return values (type-safe) ```typescript interface Test { - method(): string; + method(): string } // method property has to be the same type as method() return type -const testStub = stubInterface({ method: "stubbed" }); +const testStub = stubInterface({ method: 'stubbed' }) -expect(testStub.method()).to.equal("stubbed"); +expect(testStub.method()).to.equal('stubbed') ``` -## Object constructor stub example - -Importing stubConstructor function: - -- import single function: - -```typescript -import { stubConstructor } from "ts-sinon"; -``` +## Example -- import as part of sinon singleton: - -```typescript -import * as sinon from "ts-sinon"; - -const stubConstructor = sinon.stubConstructor; -``` - -Object constructor stub (stub all methods): +Object constructor stub (stub all methods) - without passing predefined args to the constructor: ```typescript +import { stubConstructor } from 'ts-sinon' + class Test { - public someVar: number = 10; + public someVar: number = 10 - method(): string { - return "value"; - } + method(): string { + return 'value' + } } // type will be guessed automatically -const testStub = stubConstructor(Test); +const testStub = stubConstructor(Test) -expect(testStub.method()).to.be.undefined; +expect(testStub.method()).to.be.undefined -testStub.method.returns("stubbed"); +testStub.method.returns('stubbed') -expect(testStub.method()).to.equal("stubbed"); +expect(testStub.method()).to.equal('stubbed') -expect(testStub.someVar).to.equal(10); +expect(testStub.someVar).to.equal(10) -testStub.someVar = 20; +testStub.someVar = 20 -expect(testStub.someVar).to.equal(20); +expect(testStub.someVar).to.equal(20) ``` -- with passing predefined args to the constructor: +## Example + +Passing predefined args to the constructor ```typescript class Test { - constructor(public someVar: string, y: boolean) {} - - // ... + constructor(public someVar: string, y: boolean) {} + // ... } // it won't allow to pass incorrect args -const testStub = stubConstructor(Test, "someValue", true); +const testStub = stubConstructor(Test, 'someValue', true) -expect(testStub.someVar).to.equal("someValue"); +expect(testStub.someVar).to.equal('someValue') ``` ## Sinon methods @@ -217,50 +158,30 @@ expect(testStub.someVar).to.equal("someValue"); By importing 'ts-sinon' you have access to all sinon methods. ```typescript -import sinon, { stubInterface } from "ts-sinon"; +import sinon, { stubInterface } from 'ts-sinon' -const functionStub = sinon.stub(); -const spy = sinon.spy(); +const functionStub = sinon.stub() +const spy = sinon.spy() // ... ``` -or - -```typescript -import * as tsSinon from "ts-sinon" +# Install -const functionStub = tsSinon.default.stub(); -const spy = tsSinon.default.spy(); -const tsStubInterface = tsSinon.stubInterface(); - -// ... +```console +$ npm i sinon-ts ``` -## Packages - -### Dependencies: - -1. [Microsoft/TypeScript](https://github.com/Microsoft/TypeScript) -2. [TypeStrong/ts-node](https://github.com/TypeStrong/ts-node) -3. [sinonjs/sinon](https://github.com/sinonjs/sinon) - -### Dev Dependencies: - -4. [mochajs/mocha](https://github.com/mochajs/mocha) -5. [chaijs/chai](https://github.com/chaijs/chai) -6. [domenic/sinon-chai](https://github.com/domenic/sinon-chai) - -## Tests +# API Docs -`npm test` +- -## License +# License Licensed under either of - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) - MIT ([LICENSE-MIT](LICENSE-MIT) / ) -## Contribute +# Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. diff --git a/package.json b/package.json index ec4228f..d8cb4af 100644 --- a/package.json +++ b/package.json @@ -23,15 +23,11 @@ "typescript sinon", "typescript stub" ], - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - }, "type": "module", "types": "./dist/src/index.d.ts", "files": [ "src", - "dist/src", + "dist", "!dist/test", "!**/*.tsbuildinfo" ], @@ -44,6 +40,7 @@ "eslintConfig": { "extends": "ipfs", "parserOptions": { + "project": true, "sourceType": "module" } }, @@ -137,12 +134,13 @@ "lint": "aegir lint", "build": "aegir build", "test": "aegir test", - "release": "aegir release" + "release": "aegir release", + "docs": "aegir docs" }, "devDependencies": { "@types/sinon": "^10.0.13", "@types/sinon-chai": "^3.2.8", - "aegir": "^37.5.6", + "aegir": "^41.1.4", "sinon": "^14.0.1", "sinon-chai": "^3.7.0" }, diff --git a/src/index.ts b/src/index.ts index 466adf5..7dec198 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,153 @@ +/** + * @packageDocumentation + * + * A fork of [ts-sinon](https://www.npmjs.com/package/ts-sinon) that lets you BYO sinon. Can probably be retired if [ttarnowski/ts-sinon#255](https://github.com/ttarnowski/ts-sinon/pull/255) is ever merged. + * + * - stub all object methods + * - stub interface + * - stub object constructor + * + * ## Prerequisites + * + * 1. You have a version of Node.js >= [v8.4.0](https://nodejs.org/en/download/) + * 2. You have installed [Typescript](https://www.typescriptlang.org/index.html#download-links) + * + * @example Stub all object methods + * + * ```javascript + * import { stubObject } from 'ts-sinon' + * + * class Test { + * method() { return 'original' } + * } + * + * const test = new Test() + * const testStub = stubObject(test) + * + * testStub.method.returns('stubbed') + * + * expect(testStub.method()).to.equal('stubbed') + * ``` + * + * @example Partial stub + * + * ```typescript + * class Test { + * public someProp: string = 'test' + * methodA() { return 'A: original' } + * methodB() { return 'B: original' } + * } + * + * const test = new Test() + * // second argument must be existing class method name, in this case only 'methodA' or 'methodB' are accepted. + * const testStub = stubObject(test, ['methodA']) + * + * expect(testStub.methodA()).to.be.undefined + * expect(testStub.methodB()).to.equal('B: original') + * ``` + * + * @example Stub with predefined return values (type-safe) + * + * ```typescript + * class Test { + * method() { return 'original' } + * } + * + * const test = new Test() + * const testStub = stubObject(test, { method: 'stubbed' }) + * + * expect(testStub.method()).to.equal('stubbed') + * ``` + * + * @example Interface stub (stub all methods) + * + * ```typescript + * import { stubInterface } from 'ts-sinon' + * + * interface Test { + * method(): string + * } + * + * const testStub = stubInterface() + * + * expect(testStub.method()).to.be.undefined + * + * testStub.method.returns('stubbed') + * + * expect(testStub.method()).to.equal('stubbed') + * ``` + * + * @example Interface stub with predefined return values (type-safe) + * + * ```typescript + * interface Test { + * method(): string + * } + * + * // method property has to be the same type as method() return type + * const testStub = stubInterface({ method: 'stubbed' }) + * + * expect(testStub.method()).to.equal('stubbed') + * ``` + * + * @example Object constructor stub (stub all methods) + * + * - without passing predefined args to the constructor: + * + * ```typescript + * import { stubConstructor } from 'ts-sinon' + * + * class Test { + * public someVar: number = 10 + * + * method(): string { + * return 'value' + * } + * } + * + * // type will be guessed automatically + * const testStub = stubConstructor(Test) + * + * expect(testStub.method()).to.be.undefined + * + * testStub.method.returns('stubbed') + * + * expect(testStub.method()).to.equal('stubbed') + * + * expect(testStub.someVar).to.equal(10) + * + * testStub.someVar = 20 + * + * expect(testStub.someVar).to.equal(20) + * ``` + * + * @example Passing predefined args to the constructor + * + * ```typescript + * class Test { + * constructor(public someVar: string, y: boolean) {} + * // ... + * } + * + * // it won't allow to pass incorrect args + * const testStub = stubConstructor(Test, 'someValue', true) + * + * expect(testStub.someVar).to.equal('someValue') + * ``` + * + * ## Sinon methods + * + * By importing 'ts-sinon' you have access to all sinon methods. + * + * ```typescript + * import sinon, { stubInterface } from 'ts-sinon' + * + * const functionStub = sinon.stub() + * const spy = sinon.spy() + * // ... + * ``` + */ + import sinon from 'sinon' export type StubbedInstance = sinon.SinonStubbedInstance & T @@ -10,7 +160,7 @@ export type AllowedKeys = { export type ObjectMethodsKeys = Array any>> export type ObjectMethodsMap = { - [Key in keyof T]?: T[Key] extends (...args: any[]) => any ? ReturnType : never; + [Key in keyof T]?: T[Key] extends (...args: any[]) => any ? ReturnType : never } export function stubObject (object: T, methods?: ObjectMethodsKeys | ObjectMethodsMap): StubbedInstance { diff --git a/test/index.spec.ts b/test/index.spec.ts index 4b53365..d5caed9 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -1,6 +1,5 @@ import { chai } from 'aegir/chai' import sinonChai from 'sinon-chai' - import { stubObject, stubInterface, stubConstructor } from '../src/index.js' chai.use(sinonChai) @@ -11,11 +10,11 @@ describe('ts-sinon', () => { describe('when no methods or method map given', () => { it('returns stub es6 object with all methods stubbed', () => { class A { - test () { + test (): number { return 123 } - run () { + run (): string { return 'run' } } @@ -58,20 +57,20 @@ describe('ts-sinon', () => { it('allows to change stub values', () => { const object1 = new class { - methodA () { + methodA (): string { return 'A' } - methodB () { + methodB (): string { return 'B' } }() const object2 = { - methodC: () => { + methodC: (): string => { return 'C' }, - methodD: () => { + methodD: (): string => { return 'D' } } @@ -95,18 +94,18 @@ describe('ts-sinon', () => { it('returns partial stub object with only "test" method stubbed when array with "test" has been given', () => { const object = new class { - private readonly r: string; - constructor () { - this.r = 'run' - } - - test () { - return 123 - } - - run () { - return this.r - } + private readonly r: string + constructor () { + this.r = 'run' + } + + test (): number { + return 123 + } + + run (): string { + return this.r + } }() const objectStub = stubObject(object, ['test']) @@ -119,11 +118,11 @@ describe('ts-sinon', () => { it('returns partial stub object with "run" method stubbed and returning "some val" value when key value map { run: "some val" } has been given', () => { const object = new class { - test () { + test (): number { return 123 } - run () { + run (): string { return 'run' } }() @@ -142,8 +141,8 @@ describe('ts-sinon', () => { describe('stubInterface', () => { interface ITest { prop1: string - method1: () => void - method2: (num: number) => string + method1(): void + method2(num: number): string } it('sets an "x" value on "prop1" property', () => { @@ -163,15 +162,15 @@ describe('ts-sinon', () => { }) const object = new class { - test: ITest; - constructor (test: ITest) { - this.test = test - this.test.method1() - } - - run (num: number): string { - return this.test.method2(num) - } + test: ITest + constructor (test: ITest) { + this.test = test + this.test.method1() + } + + run (num: number): string { + return this.test.method2(num) + } }(interfaceStub) expect(object.run(expectedMethod2Arg)).to.equal(expectedMethod2ReturnValue) @@ -185,15 +184,15 @@ describe('ts-sinon', () => { }) const object = new class { - test: ITest; - constructor (test: ITest) { - this.test = test - this.test.method1() - } - - run (num: number): string { - return this.test.method2(num) - } + test: ITest + constructor (test: ITest) { + this.test = test + this.test.method1() + } + + run (num: number): string { + return this.test.method2(num) + } }(interfaceStub) expect(object.run(123)).to.equal('test') @@ -218,7 +217,7 @@ describe('ts-sinon', () => { it('stubs method to return resolved Promise with another interface stub', async () => { interface Test { - methodA: () => Promise + methodA(): Promise } const interfaceTestStub = stubInterface() @@ -231,7 +230,7 @@ describe('ts-sinon', () => { it('stubs method to return rejected Promise with another interface stub', async () => { interface Test { - methodA: () => Promise + methodA(): Promise } const interfaceTestStub = stubInterface() @@ -250,20 +249,20 @@ describe('ts-sinon', () => { describe('stubConstructor', () => { it('stubs all object constructor methods', () => { class A { - // @ts-expect-error pp is not read - private readonly pp = 5; - public ps: string = 'x'; + // @ts-expect-error pp is not read + private readonly pp = 5 + public ps: string = 'x' - // @ts-expect-error pt is not read - constructor (private readonly pt: string, public px: number, y: boolean) {} + // @ts-expect-error pt is not read + constructor (private readonly pt: string, public px: number, y: boolean) {} - method1 (): string { - return 'value1' - } + method1 (): string { + return 'value1' + } - method2 (x: number): number { - return 13 - } + method2 (x: number): number { + return 13 + } } const expectedNewMethod1Value = 'new value' const expectedNewMethod2Value = 43 diff --git a/typedoc.json b/typedoc.json new file mode 100644 index 0000000..f599dc7 --- /dev/null +++ b/typedoc.json @@ -0,0 +1,5 @@ +{ + "entryPoints": [ + "./src/index.ts" + ] +}