Skip to content

Commit

Permalink
chore: add scenario outline tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Matus Sabo authored and dnotes committed Dec 17, 2024
1 parent 2626333 commit 956d422
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/main/tests/test.feature
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,33 @@ Feature: Basic Test
| 5 | 8 | 13 |
| 8 | 13 | 21 |
| 13 | 21 | 34 |

Scenario Outline: DataTables row: <Row>
Given the following datatable:
| Product | Quantity |
| <Product1> | <Qty1> |
| <Product2> | <Qty2> |
Then datatable should contain "<Product1>"

Examples:
| Row | Product1 | Qty1 | Product2 | Qty2 |
| 0 | Widget A | 2 | Widget B | 3 |
| 1 | Widget C | 1 | Widget D | 4 |

Scenario Outline: DocStrings row: <Row>
And the following json:
"""
{
"<Product1>": "<Qty1>",
"<Product2>": "<Qty2>"
}
"""
Then json should contain "<Product1>"

Examples:
| Row | Product1 | Qty1 | Product2 | Qty2 |
| 0 | Widget A | 2 | Widget B | 3 |
| 1 | Widget C | 1 | Widget D | 4 |

Rule: Vitest "todo", "skip", "fails" should work out of the box

Expand Down
19 changes: 19 additions & 0 deletions packages/main/tests/tests.steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Given('(I have )a number {int}', (world, int) => {
else world.numbers.push(int)
})

Given("the following datatable:", (world, datatable: DataTable) => {
world.datatable = datatable;
})

Given('the following numbers:', (world, numbers:DataTable) => {
world.numbers = numbers.raw().map(n => parseInt(n[0][0]))
})
Expand All @@ -45,6 +49,21 @@ Then('the sum should be {int}', (world, int) => {
expect(world.numbers.reduce((a,b) => a + b, 0)).toBe(int)
})

Then("datatable should contain {string}", (world, value) => {
const values = world.datatable
.rows()
.reduce((prev, curr) => [...curr, ...prev], []);
expect(values.includes(value)).toBe(true);
});

Then("json should contain {string}", (world, value) => {
const values = [
...Object.keys(world.json),
...(Object.values(world.json) as string[]).map((v) => v.toString()),
];
expect(values.includes(value)).toBe(true);
});

When('I set the data variable/value/property {string} to {string}', (world, prop, value) => {
if (!world.data) world.data = {}
set(world.data, prop, value)
Expand Down

0 comments on commit 956d422

Please sign in to comment.