1 | 'use strict';
|
2 |
|
3 | const rule = require('../rules/no-ajax')
|
4 | const RuleTester = require('eslint').RuleTester
|
5 |
|
6 | const ajaxError = '$.ajax is not allowed'
|
7 | const getError = '$.get is not allowed'
|
8 | const jsonError = '$.getJSON is not allowed'
|
9 | const scriptError = '$.getScript is not allowed'
|
10 | const postError = '$.post is not allowed'
|
11 |
|
12 | const ruleTester = new RuleTester()
|
13 | ruleTester.run('no-ajax', rule, {
|
14 | valid: [
|
15 | 'ajax()',
|
16 | 'div.ajax()',
|
17 | 'div.ajax',
|
18 |
|
19 | 'get()',
|
20 | 'div.get()',
|
21 | 'div.get',
|
22 |
|
23 | 'getJSON()',
|
24 | 'div.getJSON()',
|
25 | 'div.getJSON',
|
26 |
|
27 | 'getScript()',
|
28 | 'div.getScript()',
|
29 | 'div.getScript',
|
30 |
|
31 | 'post()',
|
32 | 'div.post()',
|
33 | 'div.post'
|
34 | ],
|
35 | invalid: [
|
36 | {
|
37 | code: '$.ajax()',
|
38 | errors: [{message: ajaxError, type: 'CallExpression'}]
|
39 | },
|
40 | {
|
41 | code: '$.get()',
|
42 | errors: [{message: getError, type: 'CallExpression'}]
|
43 | },
|
44 | {
|
45 | code: '$.getJSON()',
|
46 | errors: [{message: jsonError, type: 'CallExpression'}]
|
47 | },
|
48 | {
|
49 | code: '$.getScript()',
|
50 | errors: [{message: scriptError, type: 'CallExpression'}]
|
51 | },
|
52 | {
|
53 | code: '$.post()',
|
54 | errors: [{message: postError, type: 'CallExpression'}]
|
55 | }
|
56 | ]
|
57 | })
|