【发布时间】:2016-09-16 23:22:40
【问题描述】:
在试图弄清楚如何使某些 jasmine 期望语句依赖于先前的期望语句时,我发现在 Jasmine 2.3.0 之前,没有办法。 (参见Stop jasmine test after first expect fails)但是,Jasmine 2.3.0 添加了一个选项stopSpecOnExpectationFailure,当设置为 true 时,将在第一次失败时停止测试。
对这个前景感到兴奋,我修改了我的 conf.js 以包含该选项:
/*
* conf.js
*/
exports.config = {
framework: 'jasmine',
specs: ['search-spec.js'],
useAllAngular2AppRoots: true,
jasmineNodeOpts: {
stopSpecOnExpectationFailure: true
}
};
但这对我不起作用。
在我的测试中,我有:
/**
* Test option from select element is selected
*/
function verifyOptionSelected(option) {
var myEl = $('select[value="' + option + '"]';
expect(myEl.isPresent()).toBe(true, 'Option, ' + option + ', is not a value in the dropdown list. (It might be the text.)');
expect(myEl.isSelected()).toBe(true, 'Option, ' + option + ', is not selected as expected.');
}
在上面的代码中,将尝试两个 expect 语句,但如果第一个失败,我不需要尝试第二个。
你们中有人用茉莉花解决了这个问题吗?
(是的,我知道jasmine-bail-fast 和protractor-fail-fast。但是,在我看来,使用内置功能是更好的解决方案。)
【问题讨论】:
标签: javascript jasmine protractor jasmine-node