Skip to content

Commit ec89987

Browse files
oleiadeankur22
authored andcommitted
refactor: apply pull request suggestions
1 parent e9a7cc3 commit ec89987

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

docs/sources/k6/next/javascript-api/jslib/testing/_index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
---
22
title: 'testing'
33
head_title: 'testing'
4-
description: 'k6 testing library for advanced assertions and Playwright-compatible testing'
4+
description: 'k6 testing library for advanced assertions with testing inspired by Playwright patterns'
55
weight: 00
66
---
77

88
# testing
99

10-
The k6 testing library provides assertion capabilities for both protocol and browser testing, and aims for compatibility with Playwright's test API. The entire library is centered around the [`expect()`]({{< relref "./expect" >}}) function, which can be configured for convenience.
10+
The k6 testing library provides assertion capabilities for both protocol and browser testing, and draws inspiration from Playwright's test API design. The entire library is centered around the [`expect()`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jslib/k6-testing/expect) function, which can be configured for convenience.
1111

1212
{{< admonition type="note" >}}
1313
The k6 testing library source code can be found on [GitHub](https://github.com/grafana/k6-jslib-testing).
1414
{{< /admonition >}}
1515

1616
## Features
1717

18-
- **Playwright-compatible assertions**: API designed for familiarity with Playwright's testing patterns
18+
- **Playwright-inspired assertions**: API designed with patterns inspired by Playwright's testing approach
1919
- **[Protocol and browser testing](#demo)**: Works with both HTTP/API testing and browser automation
2020
- **[Auto-retrying assertions](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jslib/k6-testing/expect#retrying-assertions)**: Automatically retry assertions until they pass or timeout
2121
- **[Soft assertions](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jslib/k6-testing/expect#soft-assertions)**: Continue test execution even after assertion failures

docs/sources/k6/next/using-k6/assertions.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ weight: 04
88

99
# Assertions
1010

11-
k6 provides test assertions in the form of the `expect` function. Assertions validate that your application behaves as expected during testing.
11+
k6 provides test assertions in the form of the [`expect`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jslib/k6-testing/expect) function. Assertions validate that your application behaves as expected during testing.
1212

13-
Define assertions by passing a value to `expect()` and chaining it with a matcher that defines your expected outcome. The library provides expressive matchers that work with both protocol testing (HTTP/API) and browser testing scenarios.
13+
Define assertions by passing a value to [`expect()`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jslib/k6-testing/expect) and chaining it with a matcher that defines your expected outcome. The library provides expressive matchers that work with both protocol testing [HTTP/API](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/protocols) and [browser](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser) testing scenarios.
1414

15-
The assertions API is compatible with Playwright's assertion syntax, providing a fluent interface that improves test readability and reliability.
15+
The assertions API is inspired by Playwright's assertion syntax, providing a fluent interface that improves test readability and reliability.
1616

1717
## Getting started
1818

@@ -38,7 +38,6 @@ export async function browserTest() {
3838

3939
try {
4040
await page.goto("https://quickpizza.grafana.com/");
41-
await page.waitForLoadState("networkidle"); // waits until the `networkidle` event
4241

4342
// Assert the "Pizza Please" button is visible
4443
await expect(page.locator("button[name=pizza-please]")).toBeVisible();
@@ -109,7 +108,7 @@ export default function () {
109108

110109
### Auto-retrying assertions
111110

112-
[Auto-retrying assertions](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jslib/testing/retrying-assertions) automatically retry until conditions become true or a timeout is reached. They're designed for browser testing scenarios where elements may take time to load, update, or become interactable.
111+
[Auto-retrying assertions](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jslib/testing/retrying-assertions) automatically retry until conditions become true or a timeout is reached. They're designed for [browser testing](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser) scenarios where elements may take time to load, update, or become interactable.
113112

114113
```javascript
115114
import { expect } from 'https://jslib.k6.io/k6-testing/0.5.0/index.js';
@@ -227,7 +226,7 @@ export default function () {
227226

228227
### Soft assertions
229228

230-
Soft assertions continue test execution even when they fail, marking the test as failed but allowing subsequent assertions to run:
229+
Soft assertions continue test execution even when they fail, marking the test as failed but allowing subsequent assertions to run. Unlike [checks](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/checks), soft assertions do not measure failures or emit dedicated metrics. If you need failure-related metrics, consider using [checks](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/checks) instead:
231230

232231
```javascript
233232
import { expect } from 'https://jslib.k6.io/k6-testing/{{< param "JSLIB_TESTING_VERSION" >}}/index.js';
@@ -281,7 +280,9 @@ const configuredExpect = expect.configure({
281280
timeout: 10000, // 10 seconds for retrying assertions
282281
interval: 500, // Retry check every 500ms (on retriable assertions)
283282
colorize: true, // Enable colored output
284-
softMode: 'fail' // How soft assertions behave
283+
284+
// Setting `softMode` to 'throw', will make soft assertions fail the current iteration instead of the whole test.
285+
softMode: 'fail'
285286
});
286287

287288
export default function () {

0 commit comments

Comments
 (0)