|
| 1 | +import rule from '../../src/rules/no-nth-methods'; |
| 2 | +import { runRuleTester } from '../utils/rule-tester'; |
| 3 | + |
| 4 | +const messageId = 'noNthMethod'; |
| 5 | + |
| 6 | +runRuleTester('no-nth-methods', rule, { |
| 7 | + invalid: [ |
| 8 | + // First |
| 9 | + { |
| 10 | + code: 'page.locator("button").first()', |
| 11 | + errors: [{ column: 24, endColumn: 31, line: 1, messageId }], |
| 12 | + }, |
| 13 | + { |
| 14 | + code: 'frame.locator("button").first()', |
| 15 | + errors: [{ column: 25, endColumn: 32, line: 1, messageId }], |
| 16 | + }, |
| 17 | + { |
| 18 | + code: 'foo.locator("button").first()', |
| 19 | + errors: [{ column: 23, endColumn: 30, line: 1, messageId }], |
| 20 | + }, |
| 21 | + { |
| 22 | + code: 'foo.first()', |
| 23 | + errors: [{ column: 5, endColumn: 12, line: 1, messageId }], |
| 24 | + }, |
| 25 | + |
| 26 | + // Last |
| 27 | + { |
| 28 | + code: 'page.locator("button").last()', |
| 29 | + errors: [{ column: 24, endColumn: 30, line: 1, messageId }], |
| 30 | + }, |
| 31 | + { |
| 32 | + code: 'frame.locator("button").last()', |
| 33 | + errors: [{ column: 25, endColumn: 31, line: 1, messageId }], |
| 34 | + }, |
| 35 | + { |
| 36 | + code: 'foo.locator("button").last()', |
| 37 | + errors: [{ column: 23, endColumn: 29, line: 1, messageId }], |
| 38 | + }, |
| 39 | + { |
| 40 | + code: 'foo.last()', |
| 41 | + errors: [{ column: 5, endColumn: 11, line: 1, messageId }], |
| 42 | + }, |
| 43 | + |
| 44 | + // nth |
| 45 | + { |
| 46 | + code: 'page.locator("button").nth(3)', |
| 47 | + errors: [{ column: 24, endColumn: 30, line: 1, messageId }], |
| 48 | + }, |
| 49 | + { |
| 50 | + code: 'frame.locator("button").nth(3)', |
| 51 | + errors: [{ column: 25, endColumn: 31, line: 1, messageId }], |
| 52 | + }, |
| 53 | + { |
| 54 | + code: 'foo.locator("button").nth(3)', |
| 55 | + errors: [{ column: 23, endColumn: 29, line: 1, messageId }], |
| 56 | + }, |
| 57 | + { |
| 58 | + code: 'foo.nth(32)', |
| 59 | + errors: [{ column: 5, endColumn: 12, line: 1, messageId }], |
| 60 | + }, |
| 61 | + ], |
| 62 | + valid: [ |
| 63 | + 'page', |
| 64 | + 'page.locator("button")', |
| 65 | + 'frame.locator("button")', |
| 66 | + 'foo.locator("button")', |
| 67 | + |
| 68 | + 'page.locator("button").click()', |
| 69 | + 'frame.locator("button").click()', |
| 70 | + 'foo.locator("button").click()', |
| 71 | + 'foo.click()', |
| 72 | + ], |
| 73 | +}); |
0 commit comments