vitest-cucumber is an opiniated vitest tools (not a plugin) inspired by jest-cucumber.
Goal is to write unit test using Gherkin feature file and checking scenario name, missing scenario step etc.
npm install @amiceli/vitest-cucumber -D
It's enough you don't to add or update a config file.
Since v3.4.4
vitest-cucumber required vitest >=2.0.0
.
You can take a look on :
Vue
project example.React
project example.Scenario
function use vitest describe
function and all steps function like Given
, Then
use vitest test
function.
So you don't need to use it
or test
inside Scenario
or scenario steps.
First write your feature
file. By example :
Feature: Improve my unit tests Scenario: Use vitest-cucumber in my unit tests Given Developer using feature file And Using vitest-cucumber When I run my unit tests Then I know if I forgot a scenario
Now you can write unit tests with vitest-cucumber.
Foe example :
import { loadFeature, describeFeature } from '@amiceli/vitest-cucumber' import { expect } from 'vitest' const feature = await loadFeature('path/to/my/file.feature') describeFeature(feature, ({ Scenario }) => { Scenario('Use vitest-cucumber in my unit tests', ({ Given, When, Then, And }) => { Given('Developer using feature file', () => { expect(false).toBeFalsy() }) And('sing vitest-cucumber', () => { // ... }) When('I run my unit tests', () => { // ... }) Then('I know if I forgot a scenario', () => { // ... }) }) })
When you run your test with vitest, vitest-cucumber will check :
For example, if you forgot to write :
When('I run my unit tests', () => { // ... })
It will throw When I run my unit tests was not called.
Generate spec file from feature fileSince 3.4.1
vitest-cucumber provide a script to generate spec file from feature file.
You can use it like this :
npx @amiceli/vitest-cucumber --feature <path-to-feature> --space <path-to-spec> --lang <lang:optional>
An example :
npx @amiceli/vitest-cucumber --feature features/example.feature --spec src/__tests__/example.spec.ts --lang fr
You just have to format spec file after this script ;).
Currently it generates TS
file, if you need more options open an issue ;).
lang
allow to specify which lang is used in feature file. Required if you don't use en
language.
skip
, only
with scenario, rule and backgroundDoc is maintain in this project vitest-cucumber-docs.
Don't hesitate to open an issue on it if you want more details ;).
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4