Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cucumber-expressions

Package Overview
Dependencies
Maintainers
2
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cucumber-expressions

Cucumber Expressions - a simpler alternative to Regular Expressions

  • 8.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created

What is cucumber-expressions?

The cucumber-expressions npm package is used to define and match text patterns in Cucumber step definitions. It allows for more readable and maintainable test scenarios by using expressions to capture parameters from natural language steps.

What are cucumber-expressions's main functionalities?

Defining Cucumber Expressions

This feature allows you to define Cucumber expressions that can capture parameters from natural language steps. In this example, the expression 'I have {int} cukes' captures the integer value from the step 'I have 42 cukes'.

const { CucumberExpression, ParameterTypeRegistry } = require('cucumber-expressions');

const parameterTypeRegistry = new ParameterTypeRegistry();
const expression = new CucumberExpression('I have {int} cukes', parameterTypeRegistry);
const value = expression.match('I have 42 cukes')[0].getValue();
console.log(value); // 42

Custom Parameter Types

This feature allows you to define custom parameter types for more complex matching. In this example, a custom parameter type 'color' is defined to match the words 'red', 'blue', or 'green'.

const { ParameterTypeRegistry, ParameterType } = require('cucumber-expressions');

const parameterTypeRegistry = new ParameterTypeRegistry();
parameterTypeRegistry.defineParameterType(new ParameterType('color', /red|blue|green/, String, s => s));
const expression = new CucumberExpression('I have a {color} ball', parameterTypeRegistry);
const value = expression.match('I have a red ball')[0].getValue();
console.log(value); // 'red'

Regular Expressions

This feature allows you to use regular expressions to capture parameters from steps. In this example, the regular expression /I have (\d+) cukes/ captures the integer value from the step 'I have 42 cukes'.

const { RegularExpression, ParameterTypeRegistry } = require('cucumber-expressions');

const parameterTypeRegistry = new ParameterTypeRegistry();
const expression = new RegularExpression(/I have (\d+) cukes/, parameterTypeRegistry);
const value = expression.match('I have 42 cukes')[0].getValue();
console.log(value); // 42

Other packages similar to cucumber-expressions

Keywords

FAQs

Package last updated on 10 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc