Skip to content

Wrong place in the script is reported for failed assertions #68

@andrewslotin

Description

@andrewslotin

If an assertion fails inside a function call, the place where this function was called is reported instead of where the failing assertion is.

Here is the minimal script to reproduce the issue:

import { expect } from "https://jslib.k6.io/k6-testing/0.6.1/index.js";

export default function () {
  doTest();
}

function doTest() {
  expect(2 + 2).toBe(5);
}

When executed, the test result points to line 4 where doTest() is called instead of line 8 where the failing .toBe() assertion is:

k6 run script.js
// …
ERRO[0000] test aborted:

   Error: expect(received).toBe(expected)
      At: script.js:4:9

Expected: 5
Received: 4

Filename: test.js
    Line: 4

This makes it complicated to figure out what went wrong if a function contains multiple similar checks, e.g., validates the presence of several elements on the page.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions