【发布时间】: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