|
| 1 | +'use strict' |
| 2 | + |
| 3 | +var rule = require('../../lib/rules/no-promise-in-if') |
| 4 | +var RuleTester = require('eslint').RuleTester |
| 5 | +var eslintTester = new RuleTester() |
| 6 | + |
| 7 | +eslintTester.run('no-promise-in-if', rule, { |
| 8 | + valid: [ |
| 9 | + 'elm.isDisplayed().then(function (isDisplayed) { if (isDisplayed) { console.log("here"); } });', |
| 10 | + 'if (something) { console.log("here"); }', |
| 11 | + 'if (something) { elm.isDisplayed().then(function (isDisplayed) { if (isDisplayed) { console.log("here"); } }); }', |
| 12 | + 'if(a = isEnabled());', |
| 13 | + 'for(;;);', |
| 14 | + 'if(isSelected === "str" && typeof b){}', |
| 15 | + 'if(1, isElementPresent);', |
| 16 | + 'if(xyz === "str1" || abc==="str2" && isPresent){}' |
| 17 | + ], |
| 18 | + |
| 19 | + invalid: [ |
| 20 | + { |
| 21 | + code: 'if (elm.isDisplayed()) { console.log("here"); }', |
| 22 | + errors: [{ |
| 23 | + message: 'Unexpected "isDisplayed()" inside if condition' |
| 24 | + }] |
| 25 | + }, |
| 26 | + { |
| 27 | + code: 'if (!elm.isEnabled()) { console.log("here"); }', |
| 28 | + errors: [{ |
| 29 | + message: 'Unexpected "isEnabled()" inside if condition' |
| 30 | + }] |
| 31 | + }, |
| 32 | + { |
| 33 | + code: 'if (something) {} else if (elm.isPresent()) { console.log("here"); }', |
| 34 | + errors: [{ |
| 35 | + message: 'Unexpected "isPresent()" inside if condition' |
| 36 | + }] |
| 37 | + }, |
| 38 | + { |
| 39 | + code: 'if (something) {} else if (!browser.isElementPresent(elm)) { console.log("here"); }', |
| 40 | + errors: [{ |
| 41 | + message: 'Unexpected "isElementPresent()" inside if condition' |
| 42 | + }] |
| 43 | + }, |
| 44 | + { |
| 45 | + code: 'if (something && elm.isSelected()) { console.log("here"); }', |
| 46 | + errors: [{ |
| 47 | + message: 'Unexpected "isSelected()" inside if condition' |
| 48 | + }] |
| 49 | + }, |
| 50 | + { |
| 51 | + code: 'if (something && (elm.isSelected() || somethingelse)) { console.log("here"); }', |
| 52 | + errors: [{ |
| 53 | + message: 'Unexpected "isSelected()" inside if condition' |
| 54 | + }] |
| 55 | + }, |
| 56 | + { |
| 57 | + code: 'if (something) {} else if (something && (elm.isDisplayed() || somethingelse)) { console.log("here"); }', |
| 58 | + errors: [{ |
| 59 | + message: 'Unexpected "isDisplayed()" inside if condition' |
| 60 | + }] |
| 61 | + }, |
| 62 | + { |
| 63 | + code: 'if (something) {} else if ((!browser.isElementPresent(elm) || somethingelse) && something) { console.log("here"); }', |
| 64 | + errors: [{ |
| 65 | + message: 'Unexpected "isElementPresent()" inside if condition' |
| 66 | + }] |
| 67 | + }, |
| 68 | + { |
| 69 | + code: 'if (a === elm.isDisplayed()) { console.log("here"); }', |
| 70 | + errors: [{ |
| 71 | + message: 'Unexpected "isDisplayed()" inside if condition' |
| 72 | + }] |
| 73 | + }, |
| 74 | + { |
| 75 | + code: 'if (!elm.isDisplayed() === b) { console.log("here"); }', |
| 76 | + errors: [{ |
| 77 | + message: 'Unexpected "isDisplayed()" inside if condition' |
| 78 | + }] |
| 79 | + }, |
| 80 | + { |
| 81 | + code: 'if (b = elm.isPresent()) { console.log("here"); }', |
| 82 | + errors: [{ |
| 83 | + message: 'Unexpected "isPresent()" inside if condition' |
| 84 | + }] |
| 85 | + } |
| 86 | + ] |
| 87 | +}) |
0 commit comments