Skip to content

Latest commit

 

History

History
80 lines (55 loc) · 2.01 KB

readme.md

File metadata and controls

80 lines (55 loc) · 2.01 KB

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.