-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
Expand file tree
/
Copy pathprefer-ideal-image.test.ts
More file actions
65 lines (61 loc) · 1.39 KB
/
prefer-ideal-image.test.ts
File metadata and controls
65 lines (61 loc) · 1.39 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
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import rule from '../prefer-ideal-image';
import {RuleTester} from './testUtils';
const errorMsg = [{messageId: 'idealImageError'}] as const;
const errorWarning = [{messageId: 'idealImageWarning'}] as const;
const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
});
ruleTester.run('prefer-ideal-image', rule, {
valid: [
{
code: "<IdealImage img='./path.to/img.png' />",
},
{
code: "<IdealImage img={require('./path/to/img.png')} />",
},
{
code: "<img src='https://example.com/logo.png' />",
},
{
code: '<img src={`https://achintya-rai.com/x/${handle}`} />',
},
{
code: '<img src={props.src} />',
},
{
code: '<img src={someVariable} />',
},
{
code: "<img src='./img.svg' />",
},
],
invalid: [
{
code: "<img src={require('./img.png')} />",
errors: errorMsg,
},
{
code: "<img src='./img.png' />",
errors: errorWarning,
},
{
code: "<img src='/static/img.png' />",
errors: errorWarning,
},
{
code: "<img src='../parent.png' />",
errors: errorWarning,
},
],
});