|
| 1 | +import { runRuleTester, test } from '../utils/rule-tester' |
| 2 | +import rule from './prefer-locator' |
| 3 | + |
| 4 | +runRuleTester('prefer-locator', rule, { |
| 5 | + invalid: [ |
| 6 | + { |
| 7 | + code: test(`await page.fill('input[type="password"]', 'password')`), |
| 8 | + errors: [ |
| 9 | + { |
| 10 | + column: 34, |
| 11 | + endColumn: 81, |
| 12 | + endLine: 1, |
| 13 | + line: 1, |
| 14 | + messageId: 'preferLocator', |
| 15 | + }, |
| 16 | + ], |
| 17 | + output: null, |
| 18 | + }, |
| 19 | + { |
| 20 | + code: test(`await page.dblclick('xpath=//button')`), |
| 21 | + errors: [ |
| 22 | + { |
| 23 | + column: 34, |
| 24 | + endColumn: 65, |
| 25 | + endLine: 1, |
| 26 | + line: 1, |
| 27 | + messageId: 'preferLocator', |
| 28 | + }, |
| 29 | + ], |
| 30 | + output: null, |
| 31 | + }, |
| 32 | + { |
| 33 | + code: `page.click('xpath=//button')`, |
| 34 | + errors: [ |
| 35 | + { |
| 36 | + column: 1, |
| 37 | + endColumn: 29, |
| 38 | + endLine: 1, |
| 39 | + line: 1, |
| 40 | + messageId: 'preferLocator', |
| 41 | + }, |
| 42 | + ], |
| 43 | + output: null, |
| 44 | + }, |
| 45 | + { |
| 46 | + code: test(`await page.frame('frame-name').click('css=button')`), |
| 47 | + errors: [ |
| 48 | + { |
| 49 | + column: 34, |
| 50 | + endColumn: 78, |
| 51 | + endLine: 1, |
| 52 | + line: 1, |
| 53 | + messageId: 'preferLocator', |
| 54 | + }, |
| 55 | + ], |
| 56 | + output: null, |
| 57 | + }, |
| 58 | + { |
| 59 | + code: `page.frame('frame-name').click('css=button')`, |
| 60 | + errors: [ |
| 61 | + { |
| 62 | + column: 1, |
| 63 | + endColumn: 45, |
| 64 | + endLine: 1, |
| 65 | + line: 1, |
| 66 | + messageId: 'preferLocator', |
| 67 | + }, |
| 68 | + ], |
| 69 | + output: null, |
| 70 | + }, |
| 71 | + ], |
| 72 | + valid: [ |
| 73 | + { |
| 74 | + code: `const locator = page.locator('input[type="password"]')`, |
| 75 | + }, |
| 76 | + { |
| 77 | + code: test( |
| 78 | + `await page.locator('input[type="password"]').fill('password')`, |
| 79 | + ), |
| 80 | + }, |
| 81 | + { |
| 82 | + code: test(`await page.locator('xpath=//button').dblclick()`), |
| 83 | + }, |
| 84 | + { |
| 85 | + code: `page.locator('xpath=//button').click()`, |
| 86 | + }, |
| 87 | + { |
| 88 | + code: test( |
| 89 | + `await page.frameLocator('#my-iframe').locator('css=button').click()`, |
| 90 | + ), |
| 91 | + }, |
| 92 | + { |
| 93 | + code: test(`await page.evaluate('1 + 2')`), |
| 94 | + }, |
| 95 | + { |
| 96 | + code: `page.frame('frame-name')`, |
| 97 | + }, |
| 98 | + ], |
| 99 | +}) |
0 commit comments