Skip to content

Latest commit

 

History

History
80 lines (59 loc) · 2 KB

README.md

File metadata and controls

80 lines (59 loc) · 2 KB

npm version

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, () =>; ...)
  }
}

Any contribution following the above guidelines is really appreciated.

License

test-decorators is MIT licensed.