Skip to content

Commit

Permalink
Merge pull request #198 from Papooch/fix/scenario-outline-with-placeh…
Browse files Browse the repository at this point in the history
…olders

Fix scenario outline title placeholder to work with autoBindSteps
  • Loading branch information
bencompton committed Mar 24, 2024
2 parents 88ba27e + 8e56578 commit 3ac46fe
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { StepDefinitions, autoBindSteps, loadFeature } from '../../../../src';
import { OnlineSales } from '../../src/online-sales';

export const salesSteps: StepDefinitions = ({ given, when, then }) => {
let onlineSales: OnlineSales;
let salesPrice: number | null;

beforeEach(() => {
onlineSales = new OnlineSales();
});

given(/^I have a\(n\) (.+)$/, (item: string) => {
onlineSales.listItem(item);
});

when(/^I sell the (.+)$/, (item: string) => {
salesPrice = onlineSales.sellItem(item);
});

then(/^I should get \$(\d+)$/, (expectedSalesPrice: string) => {
expect(salesPrice).toBe(parseInt(expectedSalesPrice, 10));
});
};

const feature = loadFeature('./examples/typescript/specs/features/scenario-outlines.feature');

autoBindSteps([feature], [salesSteps]);
7 changes: 6 additions & 1 deletion src/automatic-step-binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ export const createAutoBindSteps = (jestLike: IJestLike) => {

features.forEach(feature => {
defineFeature(feature, test => {
const scenarioOutlineScenarios = feature.scenarioOutlines.map(scenarioOutline => scenarioOutline.scenarios[0]);
const scenarioOutlineScenarios = feature.scenarioOutlines.map(scenarioOutline => ({
...scenarioOutline.scenarios[0],
// we need to use the original title with un-expanded placeholders,
// otherwise it will try to match the expanded version in the feature file and fail.
title: scenarioOutline.title,
}));

const scenarios = [...feature.scenarios, ...scenarioOutlineScenarios];

Expand Down

0 comments on commit 3ac46fe

Please sign in to comment.