如果失败,如何在nightwatch.js测试失败

问题描述 投票:0回答:1

我有一个if语句,当它“失败”时,我希望它能通过我的夜班测试。

所以目前我的代码的摘录看起来像这样;

   if (rangeFacetEntry.value.length === rangePageElement.length) {
     if (JSON.stringify(rangeArray) === JSON.stringify(rangePageElement)) {
       console.log("Range - they are the same");
         return true;
           } else {
               console.log("Range - they are not the same");
                 return false;
             }
           }
     });

但是当它失败时(即JSON.stringify(rangeArray)不等于JSON.stringify(rangePageElement)),那么我希望它不能通过我的测试。

但事实并非如此。

它根本不会将结果输出到终端,整个测试通过。

有没有办法可以在我的if语句中使这个失败隐含地失败我的测试?谢谢。

javascript if-statement nightwatch.js
1个回答
0
投票

对于任何JS测试框架,“规范”都是抛出错误。

function throwIfNotEqual( a, b ) {
    if( a !== b ) {
        throw new Error( 'a !== b' );
    }

    return true;
}

if( throwIfNotEqual( 'a1', 'a1' ) ) {
    console.log( 'we are here now' );
}

if( throwIfNotEqual( 'b1', 'b2' ) ) {
    console.log( 'this will not be called because the error is thrown' );
}
© www.soinside.com 2019 - 2024. All rights reserved.