test-decorators

Typescript decorators for developing framework agnostic tests

MIT License

Downloads
13
Stars
1
Committers
1

Test Decorators

Typescript decorators for developing framework agnostic tests

Table of Contents

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/<framework-name>

Example Usage (with jest)

First build your suite decorator, using SuiteDecoratorBuilder

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

@Suite()
class MyTestSuite {
    testProp = false;
    
    @BeforeEach() setup() {
      this.testProp = true;
    }
   
    @It() 'should test'() {
      expect(this.testProp).toBeTruthy();
    }
}

Framework Adapters

The following adapters are available.

Build your own adapters

You can extend SuiteFactory to build your own adapters, and provide them to SuiteDecoratorBuilder

export class JestSuiteFactory extends SuiteFactory {
  buildSuite(target: SuiteTarget): void {
    const {suite} = target;
    // build your suite with a framework
    describe(suite.name, () =>; ...)
  }
}

Contributing

Any contribution following the above guidelines is really appreciated.

License

test-decorators is MIT licensed.

Package Rankings
Top 18.43% on Npmjs.org