Skip to content

Behaviour driven development for NestJS using jest and jest-cucumber

License

Notifications You must be signed in to change notification settings

znckco/nestjs-bdd

Repository files navigation

NestJS BDD

NPM Contributor Covenant CI codecov

Description

Behaviour driven development for NestJS using jest and jest-cucumber.

Installation

$ npm install --save nestjs-bdd

Quick Start

  1. Create matchers
import { Match, TestingContext } from "nestjs-bdd"
import { Injectable } from "@nestjs/common"

@Injectable()
export class SumMatcher {
  @Match(/^(.*) is (.*)$/)
  defineNumber(context: TestingContext, name: string, value: string) {
    context.setState(name, Number(value))
  }

  @Match(/^sum of (.*) and (.*) should be (.*)$/)
  assertSum(context: TestingContext, a: string, b: string, sum: string) {
    expect(context.getState(a) + context.getState(b)).toBe(Number(sum))
  }
}
  1. Write features
Feature: Number Operations

  Scenario: sum of two numbers
    Given a is 5
    And b is 10
    Then sum of a and b should be 15
  1. Create BDD spec file
import { AppModule } from "./AppModule" // Your app module.
import { SumMatcher } from "./test/SumMatcher" // defined in step 1.
import { TestingApp } from "nestjs-bdd"

const app = new TestingApp(AppModule, [SumMatcher])

beforeAll(() => app.start())

app.findInDir("./features") // Scan recursively for *.feature files. (e.g. defined in step 2.)

afterAll(() => app.stop())

Stay in touch

License

NestJS BDD is MIT licensed.

About

Behaviour driven development for NestJS using jest and jest-cucumber

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published