From f8fba426b094db4a69a5185fdb7ece554a200c29 Mon Sep 17 00:00:00 2001 From: ankur22 Date: Wed, 5 Jun 2024 11:09:00 +0100 Subject: [PATCH] Update check example to match others --- .../using-k6-browser/migrating-to-k6-v0-52.md | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/sources/v0.51.x/using-k6-browser/migrating-to-k6-v0-52.md b/docs/sources/v0.51.x/using-k6-browser/migrating-to-k6-v0-52.md index ed4fceb122..ce3f9bc020 100644 --- a/docs/sources/v0.51.x/using-k6-browser/migrating-to-k6-v0-52.md +++ b/docs/sources/v0.51.x/using-k6-browser/migrating-to-k6-v0-52.md @@ -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 >}} ```javascript -// Before check(page, { header: (p) => p.locator('h2').textContent() == 'Welcome, admin!', }); +``` + +{{< /code >}} + +And after: + +{{< code >}} -// After + + +```javascript const headerText = await page.locator('h2').textContent(); check(headerText, { header: headerText === 'Welcome, admin!',