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

@cucumber/cucumber-expressions

Package Overview
Dependencies
Maintainers
2
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cucumber/cucumber-expressions

Cucumber Expressions - a simpler alternative to Regular Expressions

  • 9.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
940K
decreased by-39.22%
Maintainers
2
Weekly downloads
 
Created

What is @cucumber/cucumber-expressions?

@cucumber/cucumber-expressions is a package that allows you to define and match text patterns in a way that is useful for writing and running Cucumber tests. It provides a way to define patterns that can be used to match steps in Gherkin scenarios, making it easier to write readable and maintainable test cases.

What are @cucumber/cucumber-expressions's main functionalities?

Defining Cucumber Expressions

This feature allows you to define Cucumber expressions that can be used to match text patterns in Gherkin steps. In this example, the expression 'I have {int} cukes' is defined and matched against the text 'I have 42 cukes', extracting the integer value 42.

const { CucumberExpression, ParameterTypeRegistry } = require('@cucumber/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 that can be used in Cucumber expressions. In this example, a custom parameter type 'word' is defined to match any word, and it is used in the expression 'I have a {word}', extracting the word 'cucumber'.

const { ParameterType, ParameterTypeRegistry, CucumberExpression } = require('@cucumber/cucumber-expressions');
const parameterTypeRegistry = new ParameterTypeRegistry();
parameterTypeRegistry.defineParameterType(new ParameterType('word', /\w+/, String, s => s));
const expression = new CucumberExpression('I have a {word}', parameterTypeRegistry);
const value = expression.match('I have a cucumber')[0].getValue();
console.log(value); // 'cucumber'

Regular Expressions

This feature allows you to use regular expressions to match text patterns in Gherkin steps. In this example, the regular expression /I have (\d+) cukes/ is used to match the text 'I have 42 cukes', extracting the integer value 42.

const { RegularExpression, ParameterTypeRegistry } = require('@cucumber/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/cucumber-expressions

Keywords

FAQs

Package last updated on 14 Feb 2020

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