b-yond-infinite-network / jest-cucumber-fusion

Write cucumber test the natural way but still have them part of a jest run (including coverage)
Apache License 2.0
15 stars 8 forks source link

Can't use Regex StepDef With Table #32

Open hmorey3 opened 2 years ago

hmorey3 commented 2 years ago

Hi, I am able to successfully use capture groups in regex stepdefs and separately gherkin tables in a different step def, but I can not use both in the same step def. This is something that is available in jest-cucumber, and so it's something I think should be supported here.

When I try the step def below, only the first parameter is given a value.

Then(/^a (\d+) result is returned from the endpoint&/, ((httpCode_CucumberInput: string, result_CucumberInput: string) => {
   ...
}))
j8kin commented 2 years ago

Hi, In my PR: https://github.com/b-yond-infinite-network/jest-cucumber-fusion/pull/31/files You may see step definition:

Then(/^I want to sell (\d+) items if they in list$/, (nItems, table) => {
  if (typeof nItems !== "string") return;
  if (typeof table === "string") return;
  let iNumber = Number(nItems);

  table.forEach((row) => {
    if (iNumber > 0 && onlineSales.listedItems.includes(row.Item)) {
      onlineSales.sellItem(row.Item);
      iNumber--;
    }
  });
});

And usage:

        Then I want to sell <nSale> items if they in list
            | Item               |
            | Sabaton. Great War |
            | <SaleItemName>     |

        Then I have <NItems> items for sale

        Examples:
            | nSale | SaleItemName                 | NItems |
            | 2     | Cucumber for dummies         | 2      |

And it seems this test pass. I suppose that you are talking about this behavior.

If you want to pass Gherkin table in second parameter it shouldn't be 'string' as in your example:

result_CucumberInput: string

hmorey3 commented 2 years ago

Ah yes, you're right about the string being the wrong type but I believe the issue is still there regardless.

The example you gave looks like what I want to be able to do though, although I wasn't using a scenario outline. Will your PR fix it in the case I'm not using a scenario outline?

j8kin commented 2 years ago

I suppose yes here is an example from the same test scenario (it use the same step definition):

    Scenario: Complex Scenario
        This scenario is necessary to make sure that related steps are working without examples.

        Given I have 0 items for sale

        When I bought the following items:
            | Item                         |
            | Mist written by Stephen King |
            | Metallica. ReLoad.           |
            | Sabaton. Great War           |

        Then I have 3 items for sale

        Then I want to sell 2 items if they in list
            | Item                 |
            | Sabaton. Great War   |
            | Cucumber for dummies |

And by the way actually I faced with the same issue as you are but with scenario outline. I need to double check the solution after my PR will be merge I'm not 100% sure it will fix it )))

hmorey3 commented 2 years ago

@j8kin any update on whether the PR you opened will fix the issue presented above? Thanks for your help.

j8kin commented 2 years ago

@hmorey3, I'm not the owner. Just contribute the code. @bruno-morel should approve, merge and deploy new version into NPM.

bruno-morel commented 2 years ago

let me look into the PR

bruno-morel commented 2 years ago

sorry it took so long :(