首页 > 解决方案 > 如何在柴期望中给出两个目标?

问题描述

我的量角器测试中有以下代码,

async function canSeeLoanPage(): Promise<void> {

    const header1 = element(by.tagName('h1')).getText();
    const header2 = element(by.css('section h1')).getText();
    try {
        await expect(header1).to.eventually.equal('Your Name');
    } catch (e) {
        await expect(header2).to.eventually.equal('Your Name');
    }  
}

而不是检查一个try catch,像这样给出两个目标的正确方法是什么?

await expect(header2,header2).to.eventually.equal('Your Name');

标签: chai

解决方案


我不知道比简单地使用两行代码更好的方法:

await expect(header1).to.eventually.equal('Your Name');
await expect(header2).to.eventually.equal('Your Name');

为什么需要 try catch 块?


推荐阅读