From bb9c964e0f4978a82b23d208ba64f6a4a789dc08 Mon Sep 17 00:00:00 2001 From: Anil Sharma Date: Tue, 25 Jan 2022 15:43:00 +0100 Subject: [PATCH] Handle flags of Regex expression for cucumber --- lib/interfaces/bdd.js | 4 +++- test/unit/bdd_test.js | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/interfaces/bdd.js b/lib/interfaces/bdd.js index 8da0e542e..81d8de4e6 100644 --- a/lib/interfaces/bdd.js +++ b/lib/interfaces/bdd.js @@ -25,7 +25,8 @@ const parameterTypeRegistry = new ParameterTypeRegistry(); const matchStep = (step) => { for (const stepName in steps) { if (stepName.indexOf('/') === 0) { - const res = step.match(new RegExp(stepName.slice(1, -1))); + const regExpArr = stepName.match(new RegExp('^/(.*?)/([gimy]*)$')) || []; + const res = step.match(new RegExp(regExpArr[1], regExpArr[2])); if (res) { const fn = steps[stepName]; fn.params = res.slice(1); @@ -56,6 +57,7 @@ module.exports = { Given: addStep, When: addStep, Then: addStep, + And: addStep, matchStep, getSteps, clearSteps, diff --git a/test/unit/bdd_test.js b/test/unit/bdd_test.js index 9a4b738de..d20f7b307 100644 --- a/test/unit/bdd_test.js +++ b/test/unit/bdd_test.js @@ -3,6 +3,7 @@ const { Parser } = require('gherkin'); const { Given, When, + And, Then, matchStep, clearSteps, @@ -64,10 +65,12 @@ describe('BDD', () => { it('should load step definitions', () => { Given('I am a bird', () => 1); When('I fly over ocean', () => 2); - Then(/I see (.*?)/, () => 3); + And(/^I fly over land$/i, () => 3); + Then(/I see (.*?)/, () => 4); expect(1).is.equal(matchStep('I am a bird')()); - expect(3).is.equal(matchStep('I see ocean')()); - expect(3).is.equal(matchStep('I see world')()); + expect(3).is.equal(matchStep('I Fly oVer Land')()); + expect(4).is.equal(matchStep('I see ocean')()); + expect(4).is.equal(matchStep('I see world')()); }); it('should contain tags', async () => {