Skip to content

Commit

Permalink
Update check example to match others
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur22 committed Jun 5, 2024
1 parent 9cfa86f commit f8fba42
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions docs/sources/v0.51.x/using-k6-browser/migrating-to-k6-v0-52.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,19 +334,29 @@ await text.type('hello world');

## Working with k6 check

The k6 `check` API will not `await` promises, so calling a function that returns a `Promise`, e.g. `locator.textContent()`, inside one of the predicates will not work. Instead you will have to `await` and store the result in a variable _outside_ the `check`, like so:
The k6 `check` API will not `await` promises, so calling a function that returns a `Promise`, e.g. `locator.textContent()`, inside one of the predicates will not work. Instead you will have to `await` and store the result in a variable _outside_ the `check`:

For example, before:

{{< code >}}

<!-- eslint-skip -->

```javascript
// Before
check(page, {
header: (p) => p.locator('h2').textContent() == 'Welcome, admin!',
});
```

{{< /code >}}

And after:

{{< code >}}

// After
<!-- eslint-skip -->

```javascript
const headerText = await page.locator('h2').textContent();
check(headerText, {
header: headerText === 'Welcome, admin!',
Expand Down

0 comments on commit f8fba42

Please sign in to comment.