【问题标题】:How to fail e2e Angular Protractor/Jasmine tests using expect()?如何使用 expect() 使 e2e Angular Protractor/Jasmine 测试失败?
【发布时间】:2020-06-10 13:24:59
【问题描述】:

我怎样才能使使用 Protractor/Jasmine 的 Angular e2e 测试失败?

我有这样的事情:

it(`should compare values`, async (done) => {
    try {

        const newValue: number = await pageObject.getValue();

        expect(newValue).
            withContext(`Number should increase. Is: ${newValue}, was ${oldValue}`).
            toBeGreaterThan(oldValue);

    } catch (err) {
        await testRun.fail(err);
    }
    done();
});

oldValue 在前面的步骤之一中定义(在第一个步骤之前声明)。不幸的是,此时即使两个值相等(例如 1000),也没有关于失败或类似的消息。

这样做是这样的:

if (newValue <= oldValue || (isNaN(newValue) && isNaN(oldValue))) {
    throw new Error(`Number should increase. Is: ${newValue}, was ${oldValue}`);
}

看起来可行,但我认为这不是解决此类测试的好方法。

我正在使用 Protractor 6.0.0 和 Jasmine 3.5.0。

【问题讨论】:

  • 当你说没有关于失败的消息时,你能包括你所看到的吗?
  • @DublinDev 老实说 - 我没有看到任何表明存在失败或类似情况的消息 - 没有通过 withContext 或任何其他提供的消息,就像 1000 更大1000. 当我使用throw new Error() 时,我可以看到类似“测试现在失败的原因”。我期待这样的事情:Test e2e-001, e2e-001-20200226_18205 is failing now due to: Number should increase. Is: 1021, was 1021 由 testRun 生成,但没有达到 catch 并且没有任何消息,如前所述。不幸的是,我无法包含确切的输出。
  • 还有一件事-也许我错了,因为我可以在量角器漂亮记者生成的报告中看到这一点,但我没有在 VSC 的控制台中看到它们,我预计会是显示。
  • 尝试使用许多茉莉花匹配者接受的未记录的第二个论点expect(newValue).toBeGreaterThan(oldValue),Number 应该增加。是:${newValue},是 ${oldValue};。这无法解释为什么 withContext 不起作用
  • Apolgies,格式在该评论中搞砸了 expect(newValue).toBeGreaterThan(oldValue, `Number should increase. Is: ${newValue}, was ${oldValue});`);

标签: angular jasmine protractor e2e-testing


【解决方案1】:
expect (newValue >= oldValue ).toBe(true);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-06
    • 2018-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多