Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: expect.toPass doesn't show the exact error or line number where it is failing #32702

Open
autTestUser opened this issue Sep 19, 2024 · 2 comments

Comments

@autTestUser
Copy link

autTestUser commented Sep 19, 2024

Version

1.46.0

Steps to reproduce

Run the below code which has expect.toPass inside another expect.toPass

test('my test', async ({ page }) => {
        await expect(async () => {
            await page.goto('https://www.npmjs.com/');
            await expect(async () => {
                expect(12).toBe(200);
            }).toPass({
                timeout: 5_000,
            });
        }).toPass({
            timeout: 5_000,
        });
    });

Expected behavior

Below error message should be displayed

Error: expect(received).toBe(expected) // Object.is equality

Expected: 200
Received: 12

Actual behavior

It is not showing the exact error and line number where it is failing instead it is showing below error

Error: Timeout 5000ms exceeded while waiting on the predicate

14 | timeout: 5_000,
15 | });

16 | }).toPass({
| ^
17 | timeout: 5_000,
18 | });
19 | });

Additional context

No response

Environment

System:
    OS: Linux 5.15 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (12) x64 12th Gen Intel(R) Core(TM) i7-1265U
    Memory: 2.95 GB / 7.76 GB
    Container: Yes
  Binaries:
    Node: 20.12.1 - /usr/bin/node
    npm: 10.5.0 - /usr/bin/npm
  Languages:
    Bash: 5.0.17 - /usr/bin/bash
  npmPackages:
    @playwright/test: 1.46.0 => 1.46.0
@autTestUser autTestUser changed the title [Bug]: expect.toPass doesn't show the exact line where it is failing Sep 19, 2024
@mxschmitt
Copy link
Member

This is expected, while we know what toPass is retrying in the inner toPass, we don't know in the outer toPass. Since there we just have a toPass inside which stalls.

I recommend to not nest toPass and then the good error reporting will be shown. Would that work for you?

test('my test', async ({ page }) => {
  await page.goto('https://www.npmjs.com/');
  await expect(async () => {
    expect(12).toBe(200);
  }).toPass({
    timeout: 5_000,
  });
});
@autTestUser
Copy link
Author

autTestUser commented Sep 19, 2024

Actually, it doesn't work for me. I have shown you a simple example code earlier so you may recommended not to use nested toPass. But my actual code could be something like below where I wanted method1() code also to be run repeatedly until a certain condition/assertion in method2() is passed.

test('my test', async ({ page }) => {
    await expect(async () => {
        await method1();
        await method2();
    }).toPass({
        timeout: 5_000,
    });
});

async function method2() {
    await clickOnSomething();
    await expect(async () => {
        expect(12).toBe(200);
    }).toPass({
        timeout: 5_000,
    });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants