-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathno-unmerged-classname.test.js
More file actions
71 lines (69 loc) · 1.93 KB
/
no-unmerged-classname.test.js
File metadata and controls
71 lines (69 loc) · 1.93 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const rule = require('../no-unmerged-classname')
const {RuleTester} = require('eslint')
const ruleTester = new RuleTester({
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
})
ruleTester.run('no-unmerged-classname', rule, {
valid: [
// No spread props - OK
`<Example className="foo" />`,
// Spread but no className - OK
`<Example {...rest} />`,
// className before spread (spread overrides) - OK
`<Example className="foo" {...rest} />`,
// className after spread with clsx - OK
`<Example {...rest} className={clsx(className, "foo")} />`,
// className after spread with classNames - OK
`<Example {...rest} className={classNames(className, "foo")} />`,
// className after spread with cn - OK
`<Example {...rest} className={cn(className, "foo")} />`,
// Multiple spreads but className with clsx - OK
`<Example {...rest} {...other} className={clsx(className, "foo")} />`,
],
invalid: [
// className after spread without merging - PROBLEM
{
code: `<Example {...rest} className="foo" />`,
errors: [
{
messageId: 'noUnmergedClassName',
},
],
},
// className after spread with expression but not merging function - PROBLEM
{
code: `<Example {...rest} className={myClassName} />`,
errors: [
{
messageId: 'noUnmergedClassName',
},
],
},
// className after spread with template literal - PROBLEM
{
code: `<Example {...rest} className={\`foo \${bar}\`} />`,
errors: [
{
messageId: 'noUnmergedClassName',
},
],
},
// Multiple spreads with className not merged - PROBLEM
{
code: `<Example {...rest} {...other} className="foo" />`,
errors: [
{
messageId: 'noUnmergedClassName',
},
],
},
],
})