This library is inspired by cucumber-tsflow, but leveraging NestJS as a dependency-injection container instead. This allows for a very lean implementation and is compatible with a wide array of community modules.
NOTE: This library is experimental, please report any bugs you encounter
- Install the library with your favourite package manager (e.g.:
npm install --dev @tuxmachine/nest-cucumber
) - Create an entry file to bootstrap your tests:
import { bootstrap } from '@tuxmachine/nest-cucumber';
import { AppModule } from './support/app.module';
bootstrap(AppModule);
- Start writing tests with decorators 🎉 like this
@Suite()
export class SumSteps {
private result: number;
private numbers: number[] = [];
@Given('we have an input number {int}')
addNumber(value: number) {
this.numbers.push(value);
}
@When('we calculate their sum')
calculate() {
this.result = this.numbers.reduce((x, y) => x + y);
}
@Then('it should return {int}')
verify(expected: number) {
assert.equal(this.result, expected);
}
}
- Make sure you configure Cucumber to run with ts-node, check this repo's
cucumber.js
for an example - Suites are scenario-scoped by default, mirroring NestJS request-scoped, and fresh instances are created for every scenario.
- BeforeAll and AfterAll steps run outside a scenario and thus cannot run inside scenario-scope. Make sure they're defined on a static provider.
- If you want to set a custom world, make sure you extend the NestWorld, the scenario-scoping depends on it