Skip to content

Handle flags of Regex expression for cucumber #3214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/interfaces/bdd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -56,6 +57,7 @@ module.exports = {
Given: addStep,
When: addStep,
Then: addStep,
And: addStep,
matchStep,
getSteps,
clearSteps,
Expand Down
9 changes: 6 additions & 3 deletions test/unit/bdd_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { Parser } = require('gherkin');
const {
Given,
When,
And,
Then,
matchStep,
clearSteps,
Expand Down Expand Up @@ -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 () => {
Expand Down