---
title: "Non-Retrying Assertions | Grafana k6 documentation"
description: "Synchronous assertions that evaluate immediately"
---

> For a curated documentation index, see [llms.txt](/llms.txt). For the complete documentation index, see [llms-full.txt](/llms-full.txt).

# Non-Retrying Assertions

Non-retrying assertions are synchronous assertions that allow to test any conditions, but do not auto-retry. They are ideal for testing static values, API responses, and any scenario where the expected condition should be true at the moment of evaluation.

Non-retrying assertions differ from [retrying assertions](/docs/k6/latest/javascript-api/jslib/testing/retrying-assertions/) in that they:

- **Evaluate immediately** - They check the condition once and return the result
- **Are synchronous** - They don’t need to be awaited and return results immediately
- **Have no timeout behavior** - They either pass or fail instantly
- **Are ideal for static content** - Perfect for testing values that don’t change over time

JavaScript ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```javascript
import http from 'k6/http';
import { expect } from 'https://jslib.k6.io/k6-testing/0.6.1/index.js';

export default function () {
  const response = http.get('https://quickpizza.grafana.com/');

  // Immediate assertions
  expect(response.status).toBe(200);
  expect(response.body).toBeDefined();
  expect(response.body).toBeTruthy();
  expect(typeof response.body).toBe('string');
  expect(response.body).toContain('Pizza');
}
```

## When to Use Non-Retrying Assertions

Non-retrying assertions are best suited for:

- **API response testing** - Checking status codes, response data, headers
- **Static values** - Testing constants, configuration values, or computed results
- **Data validation** - Verifying object properties, array contents, or data types
- **Known state verification** - Checking values that should be immediately available

## Non-retrying assertions methods

### Equality Assertions

Expand table

| Method                                                                                     | Description                      |
|--------------------------------------------------------------------------------------------|----------------------------------|
| [toBe()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobe/)       | Exact equality using Object.is() |
| [toEqual()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/toequal/) | Deep equality comparison         |

### Truthiness Assertions

Expand table

| Method                                                                                                 | Description            |
|--------------------------------------------------------------------------------------------------------|------------------------|
| [toBeTruthy()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobetruthy/)       | Value is truthy        |
| [toBeFalsy()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobefalsy/)         | Value is falsy         |
| [toBeDefined()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobedefined/)     | Value is not undefined |
| [toBeUndefined()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobeundefined/) | Value is undefined     |
| [toBeNull()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobenull/)           | Value is null          |

### Comparison Assertions

Expand table

| Method                                                                                                                   | Description                   |
|--------------------------------------------------------------------------------------------------------------------------|-------------------------------|
| [toBeGreaterThan()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobegreaterthan/)               | Numeric greater than          |
| [toBeGreaterThanOrEqual()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobegreaterthanorequal/) | Numeric greater than or equal |
| [toBeLessThan()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobelessthan/)                     | Numeric less than             |
| [toBeLessThanOrEqual()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobelessthanorequal/)       | Numeric less than or equal    |
| [toBeCloseTo()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobecloseto/)                       | Floating point comparison     |

### Collection Assertions

Expand table

| Method                                                                                                   | Description                                 |
|----------------------------------------------------------------------------------------------------------|---------------------------------------------|
| [toContain()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tocontain/)           | Array/string contains value                 |
| [toContainEqual()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tocontainequal/) | Array contains object with matching content |
| [toHaveLength()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tohavelength/)     | Array/string has specific length            |

### Property Assertions

Expand table

| Method                                                                                                   | Description                  |
|----------------------------------------------------------------------------------------------------------|------------------------------|
| [toHaveProperty()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tohaveproperty/) | Object has specific property |

### Type Assertions

Expand table

| Method                                                                                                   | Description                |
|----------------------------------------------------------------------------------------------------------|----------------------------|
| [toBeInstanceOf()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobeinstanceof/) | Value is instance of class |

## Common Patterns

### API Response Validation

JavaScript ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```javascript
export default function () {
  const response = http.get('https://quickpizza.grafana.com/');

  // Response status and headers
  expect(response.status).toBe(200);
  expect(response.headers['content-type']).toContain('text/html');

  // Response data structure
  expect(response.body).toBeDefined();
  expect(response.body).toBeTruthy();
  expect(response.body).toContain('pizza');
  expect(response.body).toContain('Pizza');

  // Data types
  expect(typeof response.body).toBe('string');
  expect(response.body.length).toBeGreaterThan(0);
}
```

### Data Validation

JavaScript ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```javascript
export default function () {
  const userData = {
    name: 'John Doe',
    email: 'john@example.com',
    age: 30,
    hobbies: ['reading', 'gaming'],
    address: {
      city: 'New York',
      country: 'USA',
    },
  };

  // Object structure validation
  expect(userData).toHaveProperty('name');
  expect(userData).toHaveProperty('address.city');
  expect(userData.hobbies).toHaveLength(2);

  // Value validation
  expect(userData.name).toBeDefined();
  expect(userData.email).toContain('@');
  expect(userData.age).toBeGreaterThan(0);
  expect(userData.hobbies).toContain('reading');
}
```

### Configuration Testing

JavaScript ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```javascript
export default function () {
  const config = {
    apiUrl: __ENV.API_URL || 'https://api.example.com',
    timeout: parseInt(__ENV.TIMEOUT || '5000'),
    retries: parseInt(__ENV.RETRIES || '3'),
    features: (__ENV.FEATURES || 'feature1,feature2').split(','),
  };

  // Configuration validation
  expect(config.apiUrl).toContain('http');
  expect(config.timeout).toBeGreaterThan(0);
  expect(config.retries).toBeGreaterThanOrEqual(0);
  expect(config.features).toContain('feature1');
  expect(config.features).toHaveLength(2);
}
```

## Error Handling Patterns

### Graceful Error Handling

JavaScript ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```javascript
export default function () {
  const response = http.get('https://quickpizza.grafana.com/');

  // Check response status first
  if (response.status === 200) {
    expect(response.body).toBeDefined();
    expect(response.body).toBeTruthy();
    expect(response.body).toContain('Pizza');
  } else {
    // Handle error response
    expect(response.status).toBeGreaterThanOrEqual(400);
    expect(response.body).toContain('error');
  }
}
```

- [toBe()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobe/)
- [toEqual()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/toequal/)
- [toContain()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tocontain/)
- [toBeTruthy()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobetruthy/)
- [toBeFalsy()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobefalsy/)
- [toBeDefined()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobedefined/)
- [toBeGreaterThan()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobegreaterthan/)
- [toBeCloseTo()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobecloseto/)
- [toHaveLength()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tohavelength/)
- [toHaveProperty()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tohaveproperty/)
- [toBeGreaterThanOrEqual()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobegreaterthanorequal/)
- [toBeLessThan()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobelessthan/)
- [toBeNull()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobenull/)
- [toBeUndefined()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobeundefined/)
- [toContainEqual()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tocontainequal/)
- [toBeLessThanOrEqual()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobelessthanorequal/)
- [toBeInstanceOf()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobeinstanceof/)
- [toBeNaN()](/docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobenan/)
