{"id":18576343,"url":"https://github.com/stbestichhh/stlib-testing","last_synced_at":"2026-02-09T16:06:48.139Z","repository":{"id":251798605,"uuid":"838364457","full_name":"stbestichhh/stlib-testing","owner":"stbestichhh","description":"sTest - is an testing framework for node.js applications, which provides new testing experience to the TypeScript.","archived":false,"fork":false,"pushed_at":"2025-01-01T16:30:34.000Z","size":1292,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-15T02:49:12.556Z","etag":null,"topics":["cli","decorators","library","nodejs","npm-package","testing-framework","typescript","typescript-testing-framework"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@stlib/testing","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stbestichhh.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-08-05T13:43:52.000Z","updated_at":"2025-01-01T16:30:37.000Z","dependencies_parsed_at":"2024-08-28T14:50:16.162Z","dependency_job_id":"9ebcdd0d-d719-4a74-af2a-8383b6f1a729","html_url":"https://github.com/stbestichhh/stlib-testing","commit_stats":null,"previous_names":["stbestichhh/stlib-testing"],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/stbestichhh/stlib-testing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stbestichhh%2Fstlib-testing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stbestichhh%2Fstlib-testing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stbestichhh%2Fstlib-testing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stbestichhh%2Fstlib-testing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stbestichhh","download_url":"https://codeload.github.com/stbestichhh/stlib-testing/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stbestichhh%2Fstlib-testing/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265957332,"owners_count":23855233,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","decorators","library","nodejs","npm-package","testing-framework","typescript","typescript-testing-framework"],"created_at":"2024-11-06T23:24:34.433Z","updated_at":"2026-02-09T16:06:43.104Z","avatar_url":"https://github.com/stbestichhh.png","language":"TypeScript","readme":"\u003cdiv align=\"center\"\u003e\n\n# sTest\n\n[![NPM Version](https://img.shields.io/npm/v/@stlib/testing)](https://www.npmjs.com/package/@stlib/testing)\n![NPM Downloads](https://img.shields.io/npm/d18m/%40stlib%2Ftesting)\n\n[![Node.js CI](https://github.com/stbestichhh/stlib-testing/actions/workflows/node.js.yml/badge.svg)](https://github.com/stbestichhh/stlib-utils/actions/workflows/node.js.yml)\n[![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://github.com/ellerbrock/open-source-badges/)\n[![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)\n\n**[See docs \u003e\u003e](https://stbetsichhhs-organization.gitbook.io/stest-or-typescript-testing-framework)**\n\n\u003c/div\u003e\n\n## Table of contents\n\n* [Description](#about)\n* [Getting started](#getting-started)\n  * [Command Line Interface](#cli)\n  * [Installation](#installation)\n  * [Usage](#usage)\n  * [Configuration](#configuration)  \n* [Contributing](#contributing)\n* [Changelog](#changelog)\n* [Authors](#authors)\n* [License](#license)\n\n## About\n\n**sTest** - is an testing framework for node.js applications, which provides new testing experience to the TypeScript.\n\n## Getting started\n\n\u003e [!IMPORTANT]\n\u003e **Node.js 18.x+** version must be installed in your OS.\n\n### CLI\n```text\nUsage: npx stest [options]\n\nTesting framework for TypeScript Node.js applications\n\nOptions:\n  --init [extension]   initialise configuration file [json | yml | ts | js]\n  -w, --watch          run tests in watch mode\n  -c, --config \u003cpath\u003e  define custom config file path\n```\n\n### Installation\n\n* Install dependency\n  ```shell\n  $ yarn add @stlib/testing\n  ```\n\n* Enable decorators in your `tsconfing.json`\n  ```json\n  {\n    \"experimentalDecorators\": true\n  }\n  ```\n\n### Usage\n\n#### How to create tests and run tests\n\n\u003e [!NOTE]\n\u003e You can see test examples [here](example)\n\nFirst you need is to create a `.spec.ts` or `.test.ts` file.\n\nThis testing framework uses decorators to define tests. You need to create a class with `@Test('Test suite name')` decorator. Each test must be a class method with decorator `@Case('test case description')`.\n@Case description and @Test name can be ignored\n\n**Example**:\n\n```TypeScript\nimport { assertThat, Test, Case } from '@stlib/testing';\n\n@Test('Example testing suite')\nclass MyTests {\n\n  @Case('Example pass test case')\n  checkIfTenIsMoreThatFive() {\n    assertThat(10).toBeGreaterThan(5);\n  }\n  \n  @Case()\n  checkIfTenIsString() {\n    assertThat(10).toBeTypeOf('string');\n  }\n}\n```\n\nTo run tests, use cli command\n```shell\n$ npx stest\n```\n\n#### Decorators API\n\n\u003e [!NOTE]\n\u003e You can see test examples [here](example)\n\n| Decorator                                                   | Description                                                                                                                     |\n|-------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|\n| `@Test(description?: string)`                               | Define a class as a test suite                                                                                                  |\n| `@Case(description?: string)`                               | Define method as a test case                                                                                                    |\n| `@Case({ description?: string, timeout?: number })`         | Define method as a test case with custom timeout time                                                                           |\n| `@DataSet(...dataSets: any[][])`                            | Define data sets for multiple running one test case with different data                                                         |\n| `@DataTable(dataTable: { inputs: any[], expected: any }[])` | Define data table for multiple running one test case with different data. **Data table prevents running tests with data sets.** |\n| `@AfterAll(description?: string)`                           | Force method to run after all test cases                                                                                        |\n| `@BeforeAll(description?: string)`                          | Force method to run before all test cases                                                                                       |\n| `@AfterEach(description?: string)`                          | Runs after each test case                                                                                                       |\n| `@BeforeEach(description?: string)`                         | Runs before each test case                                                                                                      |\n\n#### Assertions API\n`assertThat(actual).to*(expected);`\n\n| Method                                                         | Description                                                                                                                                             |\n|----------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `toEqual(expected: any)`                                       | Check equality between actual and expected                                                                                                              |\n| `toNotEqual(expected: any)`                                    | Check if actual and expected are not equal                                                                                                              |\n| `toStrictEqual(expected: any)`                                 | Check strict equality between actual and expected                                                                                                       |\n| `toStrictNotEqual(expected: any)`                              | Check if actual and expected are strict not equal                                                                                                       |\n| `toBe(expected: any)`                                          | Check if actual is an expected                                                                                                                          |\n| `toNotBe(expected: any)`                                       | Check if actual is not an expected                                                                                                                      |\n| `toObjectEqual(expected: any)`                                 | Check if two objects or arrays are equal                                                                                                                |\n| `toBeTruthy()`                                                 | Check if actual is true                                                                                                                                 |\n| `toBeFalsy()`                                                  | Check if actual is false                                                                                                                                |\n| `toBeGreaterThan(expected: number)`                            | Check if actual is greater than expected                                                                                                                |\n| `toBeGreaterThanOrEqual(expected: number)`                     | Check if actual is greater than or equals expected                                                                                                      |\n| `toBeLessThan(expected: number)`                               | Check if actual is less than expected                                                                                                                   |\n| `toBeLessThanOrEqual(expected: number)`                        | Check if actual is less than or equal expected                                                                                                          |\n| `toBeDefined()`                                                | Check if actual is defined                                                                                                                              |\n| `toBeUndefined()`                                              | Check if actual is undefined                                                                                                                            |\n| `toBeNull()`                                                   | Check if actual is null                                                                                                                                 |\n| `toBeNotNull()`                                                | Check if actual is not null                                                                                                                             |\n| `toBeNaN()`                                                    | Check if actual is NaN                                                                                                                                  |\n| `toBeFinite()`                                                 | Check if actual is finite number                                                                                                                        |\n| `toBeTypeOf(type: any)`                                        | Check if actual is type of expected. Example: `assertThat('a').toBeTypeOf('string')`, `assertThat(TypeError).toBeTypeOf(Error)`                         |\n| `toHaveProperty(property: any)`                                | Check if actual has expected property                                                                                                                   |\n| `toHavePropertyEqual(property: any, value: any)`               | Check if actual has expected property which is equal to value                                                                                           |\n| `toHaveAllProperties(properties: any[])`                       | Check if actual has all of expected properties                                                                                                          |\n| `toHaveAnyProperties(properties: any[])`                       | Check if actual has any of expected properties                                                                                                          |\n| `toThrow(expectedError?: ErrorConstructor, ...args: any[])`    | Check if actual throw an error or expected error. Also you can provide arguments for actual function                                                    |\n| `toNotThrow(expectedError?: ErrorConstructor, ...args: any[])` | Check if actual do not throw an error or do not throw an error provided to as 'expectedError' param. Also you can provide arguments for actual function |\n| `toContain(expected: any)`                                     | Check if actual contains a value from expected                                                                                                          |\n| `toContainEqual(expected: any)`                                | Check if actual contains a value which equal to value from expected                                                                                     |\n| `toMatch(expected: RegExp or string)`                          | Check if actual mathes to expected regular expression                                                                                                   |\n| `toHaveLength(expected: number)`                               | Check if actual has expected length                                                                                                                     |\n| `toStartWith(expected: string)`                                | Check if actual starts with expected string                                                                                                             |\n| `toEndWith(expected: string)`                                  | Check if actual ends with expected string                                                                                                               |\n| `toSatisfy(predicate: (value: any) =\u003e boolean)`                | Check if actual satisfies a predicate                                                                                                                   |\n| `toIncludeAllMembers(expected: any[])`                         | Check if actual includes all members of expected array                                                                                                  |\n| `toIncludeAnyMembers(expected: any[])`                         | Check if actual includes at least one member of expected array                                                                                          |\n| `toMatchSnapshot(snapshotName?: string)`                       | Matches actual data with the last created snapshot, or chosen one with using name                                                                       |\n\n#### Mocking API\n \n| Class          | Method                                                                      | Description                                               |\n|----------------|-----------------------------------------------------------------------------|-----------------------------------------------------------|\n| `MockRegistry` | `restoreAll()`                                                              | Restores all created mocks                                |\n| `MockFn`       | `new MockFn(functionToMock: Function, implementation?: Function)`           | Creates function mock                                     |\n|                | `mockFn.mock(implementation?: Function)`                                    | Mocks a function                                          |\n|                | `mockFn.verifyCalled(expectedCallcount: number)`                            | Verifies function has been called expected times          |\n|                | `mockFn.verifyCalledWith(expectedArguments: any[])`                         | Verifies function has been called with expected arguments |\n|                | `mockFn.restore()`                                                          | Restores original function logic                          |\n|                | `mockFn.getFunction()`                                                      | Returns fuction                                           |\n|                | `mockFn.call(...args: any[])`                                               | Call function                                             |\n| `MockModule`   | `new MockModule(moduleName: string)`                                        | Creates module mock                                       |\n|                | `mockModule.mockMethod(methodName: string, implementation: Function)`       | Mocks a function                                          |\n|                | `mockModule.verifyCalled(methodName: string, expectedCallcount: number)`    | Verifies function has been called expected times          |\n|                | `mockModule.verifyCalledWith(methodName: string, expectedArguments: any[])` | Verifies function has been called with expected arguments |\n|                | `mockModule.restoreMethod(methodName: string)`                              | Restores original function logic                          |\n|                | `mockModule.restoreAll()`                                                   | Restores all functios                                     |\n| `Mock`         | `new Mock(instance: T)`                                                     | Creates class instance mock                               |\n|                | `mockClass.mockMethod(methodName: string, implementation: Function)`        | Mocks a function                                          |\n|                | `mockClass.verifyCalled(methodName: string, expectedCallcount: number)`     | Verifies function has been called expected times          |\n|                | `mockClass.verifyCalledWith(methodName: string, expectedArguments: any[])`  | Verifies function has been called with expected arguments |\n|                | `mockClass.restoreMethod(methodName: string)`                               | Restores original function logic                          |\n|                | `mockClass.restoreAll()`                                                    | Restores all functios                                     |\n\n#### Spy API\n\nCreate a new spy by `spyOn(instance: any, methodName: string)` function:\n\n* Spy methods:\n  ```TypeScript\n  const example = new ExampleClass();\n  const greetSpy = spyOn(example, 'greet');\n  \n  // Call method\n  example.greet('Hello, World!');\n  ```\n* Spy functions\n  ```TypeScript\n  const func = () =\u003e { return 'Hello' };\n  const greetSpy = spyOn(func);\n  \n  // Call function  \n  greetSpy.call('Hello, World!');\n  greetSpy.getCallCount(); // 1\n  \n  // Spy won't work for calling function directly\n  func('Hello, World!'); // still 1\n  ```\n\n| Class                                    | Method                                | Description                                                                 |\n|------------------------------------------|---------------------------------------|-----------------------------------------------------------------------------|\n| `spyOn(object: any, methodName: string)` |                                       | Creates new spy on class method                                             |\n|                                          | `getCallCount()`                      | Returns amount of method calls                                              |\n|                                          | `getCallOrder()`                      | Returns an array with call order                                            |\n|                                          | `getCallResults(callIndex?: number)`  | Returns an array with call results                                          |\n|                                          | `getCallArgs(callIndex?: number)`     | Returns an array with arguments passed                                      |\n|                                          | `getThrownErrors(callIndex?: number)` | Returns an array with with all thrown errors                                |\n|                                          | `wasCalled(amount?: number)`          | Returns true if method was called at least once or more than `amount` times |\n|                                          | `wasCalledWith(...args: any[])`       | Returns true if method was called with specified arguments at least once    |\n|                                          | `call(...args: any[])`                | Calls spied function                                                        |\n\n#### Snapshots API\n\nCreate a new snapshot by `shot(snapshotName: string, data: any)` function:\n```TypeScript\nshot('snap', '\u003ch1\u003eHello\u003c/h1\u003e');\nshot('other snap', '\u003ch1\u003eBye\u003c/h1\u003e');\n\nassertThat('\u003ch1\u003eBye\u003c/h1\u003e').toMatchSnapshot();\nassertThat('\u003ch1\u003eHello\u003c/h1\u003e').toMatchSnapshot('snap');\n```\n\n#### Configuration\nTo provide custom configuration for `stest` create `stest.config.{json,yml,ts,js}` file in project base directory. \\\nOr use this command to initialize config file. By default it has `json` format. Override it by adding one of the possible options for the `--init` flag: `ts, js, json, yml`\n```shell\n$ npx stest --init\n```\n\nAlso it is possible to define custom path to the config file using `--config` flag.\n```shell\n$ npx stest --config ./configs/test.conf.yml\n```\n\nConfig properties:\n* pattern - tests path pattern\n* ignore - files and directories to ignore\n* autoClearMocks - clears all created mocks after each test,\n* cacheWatcher - enables caching in watch mode, to run only new or changed tests\n* enableReporting - enables generating test reports.\nTo enable it install a reporting package: \n  ```shell\n  $ yarn add @stlib/testing-reporter\n  ```\n\nConfig file example:\n\n  * json:\n    ```json\n    {\n      \"pattern\": \"test/**/*.{spec,test}.ts\",\n      \"ignore\": [\"node_modules\", \"lib\"],\n      \"autoClearMocks\": true,\n      \"cacheWatcher\": false,\n      \"enableReporting\": false\n    }\n    ```\n\n  * yaml:\n    ```yaml\n    pattern: \"test/**/*.{spec,test}.ts\"\n    ignore:\n      - node_modules\n      - lib\n    autoClearMocks: true\n    cacheWatcher: false\n    enableReporting: false\n    ```\n  \n  * TS/JS:\n    ```TypeScript\n    import { StestConfig } from \"@stlib/testing\";\n\n    const config: StestConfig = {\n      pattern: \"test/**/*.{spec,test}.ts\",\n      ignore: [\"node_modules\", \"lib\"],\n      autoClearMocks: true,\n      cacheWatcher: false,\n      enableReporting: false,\n    };\n    export default config;\n    ```\n\n## Contributing\n\nPlease read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.\n\n## Changelog\n\nProject changes are writen in changelog, see the [CHANGELOG.md](CHANGELOG.md).\n\nWe use [SemVer](https://semver.org/) for versioning.\nFor the versions available, see the [tags](https://github.com/stbestichhh/stlib-testing/tags) on this repository.\nFor the versions supported, see the [SECURITY.md](SECURITY.md).\n\n## Authors\n\n- [@stbestichhh](https://www.github.com/stbestichhh)\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE.md](LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstbestichhh%2Fstlib-testing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstbestichhh%2Fstlib-testing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstbestichhh%2Fstlib-testing/lists"}