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.
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:
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: 4This 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.