小编Mar*_*nco的帖子

如何停止 Jest 在测试输出中包装 `console.log`?

我正在根据请求进行 Jest 测试

describe("GET /user ", () => {
    test("It should respond with a array of users", done => {
        return request(url, (err, res, body) => {
            if (err) {
                console.log(err)
            } else {
                console.log("GET on " + url);
                body = JSON.parse(body);
                expect(body.length).toBeGreaterThan(0);
                done();
            }
        })
    })
});
Run Code Online (Sandbox Code Playgroud)

这很奇怪,因为在终端中,jest 将 console.log 行显示为输出的一部分:

 ...test output...

  console.log test/modules/user.test.js:18
    GET on https://xpto/api/user

...more test output...
Run Code Online (Sandbox Code Playgroud)

我需要隐藏该行:

console.log test/modules/user.test.js:18
Run Code Online (Sandbox Code Playgroud)

如何在 Jest 输出中隐藏 console.log 行?

console.log jestjs

6
推荐指数
2
解决办法
4197
查看次数

如何断言 HTML 元素是 Playwright 中的有效链接?

我正在尝试在Playwright中做一些断言。我需要断言,在链接列表中,<a>所有链接都具有该属性href。但是,我不知道如何使用剧作家功能来实现这一点。

我的代码在这里:

test.only('then a list of 44 links is displayed', async({ page }) => {
         const linkList = await page.locator('div#content > ul > li > a');
         for(let i = 0; i < await linkList.count(); i++) {
             expect(await linkList.nth(i)).toHaveAttribute('href', '');             }
         await expect(linkList).toHaveCount(44);
    })
Run Code Online (Sandbox Code Playgroud)

toHaveAttribute()函数需要 2 到 3 个参数,因为它获取键属性和属性的值,但我只需要检查它是否具有 href 属性。

我怎样才能做到这一点?

这是正在测试的网站: https ://the-internet.herokuapp.com/

html javascript automated-tests playwright

5
推荐指数
1
解决办法
5747
查看次数