|
| 1 | +import test from 'ava'; |
| 2 | +import avaRuleTester from 'eslint-ava-rule-tester'; |
| 3 | +import rule from '../rules/test-title-format'; |
| 4 | + |
| 5 | +const ruleTester = avaRuleTester(test, { |
| 6 | + env: { |
| 7 | + es6: true |
| 8 | + } |
| 9 | +}); |
| 10 | + |
| 11 | +const errors = [{ruleId: 'test-title-format'}]; |
| 12 | +const header = 'const test = require(\'ava\');\n'; |
| 13 | + |
| 14 | +ruleTester.run('test-title-format', rule, { |
| 15 | + valid: [ |
| 16 | + header + 'test("Foo", t => { t.pass(); });', |
| 17 | + { |
| 18 | + code: header + 'test("Foo", t => { t.pass(); });', |
| 19 | + options: [{format: '.'}] |
| 20 | + }, |
| 21 | + { |
| 22 | + code: header + 'test("Should pass tests.", t => { t.pass(); });', |
| 23 | + options: [{format: '^Should .+\\.$'}] |
| 24 | + }, |
| 25 | + { |
| 26 | + code: header + 'test.todo("Should pass tests.");', |
| 27 | + options: [{format: '^Should .+\\.$'}] |
| 28 | + }, |
| 29 | + { |
| 30 | + code: header + 'test(t => { t.pass(); });', |
| 31 | + options: [{format: '^Should'}] |
| 32 | + }, |
| 33 | + { |
| 34 | + code: header + 'notTest("Foo", t => { t.pass(); });', |
| 35 | + options: [{format: '^Should'}] |
| 36 | + }, |
| 37 | + { |
| 38 | + code: header + 'test(macro, t => { t.pass(); });', |
| 39 | + options: [{format: '^Should'}] |
| 40 | + }, |
| 41 | + // Shouldn't be triggered since it's not a test file |
| 42 | + { |
| 43 | + code: 'test("Test", t => { t.pass(); });', |
| 44 | + options: [{format: '^Should'}] |
| 45 | + } |
| 46 | + ], |
| 47 | + invalid: [ |
| 48 | + { |
| 49 | + code: header + 'test("Test something", t => { t.pass(); });', |
| 50 | + options: [{format: '^Should'}], |
| 51 | + errors |
| 52 | + }, |
| 53 | + { |
| 54 | + code: header + 'test.todo("Test something");', |
| 55 | + options: [{format: '^Should'}], |
| 56 | + errors |
| 57 | + } |
| 58 | + ] |
| 59 | +}); |
0 commit comments