Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kaosdev/test-decorators

Typescript decorators for developing framework agnostic tests
https://github.com/kaosdev/test-decorators

decorators jasmine jest mocha testing typescript unit-testing

Last synced: 22 days ago
JSON representation

Typescript decorators for developing framework agnostic tests

Awesome Lists containing this project

README

        


npm version

# Test Decorators
> Typescript decorators for developing framework agnostic tests

## Table of Contents

- [Getting Started](#getting-started)
- [Code of Conduct](#code-of-conduct)
- [Contributing](#contributing)
- [License](#license)

## Getting Started

### Installing

To work with decorators you need to install the core package and a framework adapter package.
```
npm install @test-decorators/core
npm install @test-decorators/
```

### Example Usage (with jest)

First build your suite decorator, using SuiteDecoratorBuilder
```typescript
import {SuiteDecoratorBuilder} from '@test-decorators/core';
import {JestSuiteFactory} from '@test-decorators/jest';

export const Suite = new SuiteDecoratorBuilder(
new JestSuiteFactory()
).build();
```

Then use it to build your test suites
```typescript
@Suite()
class MyTestSuite {
testProp = false;

@BeforeEach() setup() {
this.testProp = true;
}

@It() 'should test'() {
expect(this.testProp).toBeTruthy();
}
}
```

### Framework Adapters

The following adapters are available.
- [Jest](packages/jest/README.md) npm version

### Build your own adapters
You can extend SuiteFactory to build your own adapters, and provide them to SuiteDecoratorBuilder
```typescript
export class JestSuiteFactory extends SuiteFactory {
buildSuite(target: SuiteTarget): void {
const {suite} = target;
// build your suite with a framework
describe(suite.name, () =>; ...)
}
}

```

## [Contributing](CONTRIBUTING.md)

- Read our [code of conduct](CODE_OF_CONDUCT.md)
- Read our [contributing guide](CONTRIBUTING.md)

Any contribution following the above guidelines is really appreciated.

## License

test-decorators is [MIT licensed](LICENSE).