jest-cucumber icon indicating copy to clipboard operation
jest-cucumber copied to clipboard

Support Cucumber Expressions

Open pietmichal opened this issue 6 years ago • 2 comments
trafficstars

https://cucumber.io/docs/cucumber/cucumber-expressions/

"User enters {string} name" is much nicer than /^User enters (.*) name$/.

pietmichal avatar Aug 20 '19 10:08 pietmichal

Agreed, this would be great to support.

bencompton avatar Sep 26 '19 15:09 bencompton

I need that feature on my current project, I gave a try on this feature

I've concerned several approaches

  • use cucumber-expression lib
  • string preprocessing to detect if it contains {int} {string} etc. and then evaluate to RegExp
  • add CucumberExpression as a type of step matcher

Currently I've done POC using second approach - string preprocessing, replace {int} {string} with corresponding regex,

    '{int}': '\\$(\\d+)',
    '{double}': '^(-?)(0|([1-9][0-9]*))(\\.[0-9]+)?$',
    '{string}': '"(.*)"', // example

It might seem quite hacky but works for me.

image image

kstarzyk avatar Nov 22 '19 11:11 kstarzyk