Skip to content

Commit

Permalink
docs: add note for passing world when re-use step fn
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalets committed Dec 17, 2024
1 parent 8983c45 commit d6d7fac
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions docs/writing-steps/reusing-step-fn.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,24 @@ const createTodo = When('I create todo {string}', async ({ page }, text: string)
await page.getByRole('button').click();
});

When(
'I create 2 todos {string} and {string}',
async ({ page }, text1: string, text2: string) => {
await createTodo({ page }, text1);
await createTodo({ page }, text2);
},
);
```
When('I create 2 todos {string} and {string}', async ({ page }, text1: string, text2: string) => {
await createTodo({ page }, text1);
await createTodo({ page }, text2);
});
```

#### Passing World

For **cucumber-style steps** you should invoke step function via `.call()` to pass actual World:

```js
const createTodo = When('I create todo {string}', async function (text: string) {
await this.page.getByLabel('title').fill(text);
await this.page.getByRole('button').click();
});

When('I create 2 todos {string} and {string}', async function (text1: string, text2: string) {
await createTodo.call(this, text1);
await createTodo.call(this, text2);
});
```

0 comments on commit d6d7fac

Please sign in to comment.