Skip to content

Commit a6e41cf

Browse files
anils92anilwk
andauthored
Handle flags of Regex expression for cucumber (#3214)
Co-authored-by: Anil Sharma <[email protected]>
1 parent 12009e0 commit a6e41cf

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lib/interfaces/bdd.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ const parameterTypeRegistry = new ParameterTypeRegistry();
2525
const matchStep = (step) => {
2626
for (const stepName in steps) {
2727
if (stepName.indexOf('/') === 0) {
28-
const res = step.match(new RegExp(stepName.slice(1, -1)));
28+
const regExpArr = stepName.match(new RegExp('^/(.*?)/([gimy]*)$')) || [];
29+
const res = step.match(new RegExp(regExpArr[1], regExpArr[2]));
2930
if (res) {
3031
const fn = steps[stepName];
3132
fn.params = res.slice(1);
@@ -56,6 +57,7 @@ module.exports = {
5657
Given: addStep,
5758
When: addStep,
5859
Then: addStep,
60+
And: addStep,
5961
matchStep,
6062
getSteps,
6163
clearSteps,

test/unit/bdd_test.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const { Parser } = require('gherkin');
33
const {
44
Given,
55
When,
6+
And,
67
Then,
78
matchStep,
89
clearSteps,
@@ -64,10 +65,12 @@ describe('BDD', () => {
6465
it('should load step definitions', () => {
6566
Given('I am a bird', () => 1);
6667
When('I fly over ocean', () => 2);
67-
Then(/I see (.*?)/, () => 3);
68+
And(/^I fly over land$/i, () => 3);
69+
Then(/I see (.*?)/, () => 4);
6870
expect(1).is.equal(matchStep('I am a bird')());
69-
expect(3).is.equal(matchStep('I see ocean')());
70-
expect(3).is.equal(matchStep('I see world')());
71+
expect(3).is.equal(matchStep('I Fly oVer Land')());
72+
expect(4).is.equal(matchStep('I see ocean')());
73+
expect(4).is.equal(matchStep('I see world')());
7174
});
7275

7376
it('should contain tags', async () => {

0 commit comments

Comments
 (0)