https://github.com/rickdgeerling/nest-cucumber
Structure Cucumber tests with NestJS
https://github.com/rickdgeerling/nest-cucumber
bdd cucumber nestjs testing
Last synced: 17 days ago
JSON representation
Structure Cucumber tests with NestJS
- Host: GitHub
- URL: https://github.com/rickdgeerling/nest-cucumber
- Owner: rickdgeerling
- License: mit
- Created: 2022-12-16T10:32:25.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-10-31T06:01:19.000Z (6 months ago)
- Last Synced: 2025-04-10T19:39:02.848Z (18 days ago)
- Topics: bdd, cucumber, nestjs, testing
- Language: TypeScript
- Homepage:
- Size: 184 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Nest-Cucumber
This library is inspired by
[cucumber-tsflow](https://github.com/timjroberts/cucumber-js-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
## Usage
1. Install the library with your favourite package manager (e.g.: `npm install --dev @tuxmachine/nest-cucumber`)
2. Create an entry file to bootstrap your tests:```ts
import { bootstrap } from '@tuxmachine/nest-cucumber';
import { AppModule } from './support/app.module';bootstrap(AppModule);
```3. Start writing tests with decorators 🎉 like [this](./tests/support/step-definitions/scenario-scoped-suite.steps.ts)
```ts
@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);
}
}
```## Notes
- Make sure you configure Cucumber to run with ts-node, check this repo's
[`cucumber.js`](./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