scope-test.js
1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* eslint-env jest */
/**
* @fileoverview Enforce scope prop is only used on <th> elements.
* @author Ethan Cohen
*/
// -----------------------------------------------------------------------------
// Requirements
// -----------------------------------------------------------------------------
import { RuleTester } from 'eslint';
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
import rule from '../../../src/rules/scope';
// -----------------------------------------------------------------------------
// Tests
// -----------------------------------------------------------------------------
const ruleTester = new RuleTester();
const expectedError = {
message: 'The scope prop can only be used on <th> elements.',
type: 'JSXAttribute',
};
ruleTester.run('scope', rule, {
valid: [
{ code: '<div />;' },
{ code: '<div foo />;' },
{ code: '<th scope />' },
{ code: '<th scope="row" />' },
{ code: '<th scope={foo} />' },
{ code: '<th scope={"col"} {...props} />' },
{ code: '<Foo scope="bar" {...props} />' },
].map(parserOptionsMapper),
invalid: [
{ code: '<div scope />', errors: [expectedError] },
].map(parserOptionsMapper),
});