[prototype] Functional testing primitives for k6
APACHE-2.0 License
A seamless way to write functional tests in k6 with Playwright-compatible assertions.
⚠️ Note: This is a prototype project demonstrating the concept. Not yet ready for production use.
assert
, scale up to expressive expect
assertions as your needs growdeno task build
import { expect } from "https://github.com/oleiade/k6-testing/releases/download/v0.1.0/index.js";
export default function () {
// Simple assertions
expect(response.status).toBe(200);
// Async assertions with retry (perfect for UI testing)
await expect(page.locator('.submit-button')).toBeEnabled();
// Soft assertions - continue testing even after failures
expect.soft(data.userId).toBeDefined();
}
Use the same assertions you know from Playwright:
// These Playwright assertions work exactly the same in k6
await expect(page.locator('.button')).toBeVisible();
await expect(page.locator('input')).toHaveValue('test');
Perfect for UI testing, these assertions automatically retry until they pass or timeout:
Assertion | Description |
---|---|
toBeChecked() |
Element is checked |
toBeDisabled() |
Element is disabled |
toBeEditable() |
Element is editable |
toBeEnabled() |
Element is enabled |
toBeHidden() |
Element is hidden |
toBeVisible() |
Element is visible |
toHaveValue(value) |
Element has specific value |
For immediate validation without retry:
Assertion | Description |
---|---|
toBe(expected) |
Strict equality comparison |
toEqual(expected) |
Deep equality comparison |
toBeCloseTo(number, precision?) |
Number comparison with precision |
toBeTruthy() |
Truthy value check |
toBeFalsy() |
Falsy value check |
toBeGreaterThan(number) |
Greater than comparison |
toBeLessThan(number) |
Less than comparison |
Keep tests running even after failures - perfect for collecting multiple failures in one run:
// Test continues even if assertions fail
expect.soft(response.status).toBe(200);
expect.soft(data.items).toHaveLength(5);
Low-level assertions for simple cases:
import { assert, assertEquals } from "k6-testing";
assert(condition, "error message");
assertEquals(actual, expected, "error message");
k6-testing offers multiple layers of assertion capabilities:
assert()
for straightforward checksexpect()
for more expressive assertionsGet clear, actionable error messages:
expect(value).toBe(expected);
// Error: Expected value to be undefined
// Expected: undefined
// Received: "actual value"
Contributions are welcome! Check out our Contributing Guide for details.