|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const check = createRuleChecker('vuex/store-watch-with-string') |
| 4 | + |
| 5 | +describe('Rule: store-watch-with-string', () => { |
| 6 | + it('does not match an empty line', () => { |
| 7 | + const warning = check('') |
| 8 | + expect(warning).toBe(null) |
| 9 | + }) |
| 10 | + |
| 11 | + it('does not match store.watch with no arguments', () => { |
| 12 | + const warning = check(` |
| 13 | + store.watch( |
| 14 | + `) |
| 15 | + expect(warning).toBe(null) |
| 16 | + }) |
| 17 | + |
| 18 | + it('does not match store.watch with arrow function arg', () => { |
| 19 | + const warning = check(` |
| 20 | + store.watch(state => { |
| 21 | + `) |
| 22 | + expect(warning).toBe(null) |
| 23 | + }) |
| 24 | + |
| 25 | + it('does not match store.watch with regular function arg', () => { |
| 26 | + const warning = check(` |
| 27 | + store.watch(function (state) { |
| 28 | + `) |
| 29 | + expect(warning).toBe(null) |
| 30 | + }) |
| 31 | + |
| 32 | + it('matches store.watch with a string argument', () => { |
| 33 | + const warning = check(` |
| 34 | + store.watch('user.notifications', callback) |
| 35 | + `) |
| 36 | + expect(warning).toBeTruthy() |
| 37 | + expect(warning.fix).toBe('Update store.watch to use a function rather than a string path for the first argument (see link below for an example)') |
| 38 | + }) |
| 39 | + |
| 40 | + it('matches store.watch with a string argument and a bunch of spaces', () => { |
| 41 | + const warning = check(` |
| 42 | + store . watch ( 'user.notifications' , callback) |
| 43 | + `) |
| 44 | + expect(warning).toBeTruthy() |
| 45 | + expect(warning.fix).toBe('Update store.watch to use a function rather than a string path for the first argument (see link below for an example)') |
| 46 | + }) |
| 47 | + |
| 48 | + it('matches store.watch with a string argument using double quotes', () => { |
| 49 | + const warning = check(` |
| 50 | + store.watch('user.notifications', callback) |
| 51 | + `) |
| 52 | + expect(warning).toBeTruthy() |
| 53 | + expect(warning.fix).toBe('Update store.watch to use a function rather than a string path for the first argument (see link below for an example)') |
| 54 | + }) |
| 55 | + |
| 56 | + it('matches store.watch with a string argument using backticks', () => { |
| 57 | + const warning = check(` |
| 58 | + store.watch(\`user.notifications\`, callback) |
| 59 | + `) |
| 60 | + expect(warning).toBeTruthy() |
| 61 | + expect(warning.fix).toBe('Update store.watch to use a function rather than a string path for the first argument (see link below for an example)') |
| 62 | + }) |
| 63 | +}) |
0 commit comments