-
-
Notifications
You must be signed in to change notification settings - Fork 414
/
index.test.ts
41 lines (35 loc) 路 1.15 KB
/
index.test.ts
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
import { transform } from '@babel/core'
import plugin, { Options } from '.'
const testPlugin = (code: string, options?: Options) => {
const result = transform(code, {
plugins: ['@babel/plugin-syntax-jsx', [plugin, options]],
configFile: false,
})
return result?.code
}
describe('plugin', () => {
it('replaces width / height attributes', () => {
expect(
testPlugin('<svg foo="bar" width="100" height="200" />'),
).toMatchInlineSnapshot(
`"<svg foo=\\"bar\\" width=\\"1em\\" height=\\"1em\\" />;"`,
)
})
it('adds theme if they are not present', () => {
expect(testPlugin('<svg foo="bar" />')).toMatchInlineSnapshot(
`"<svg foo=\\"bar\\" width=\\"1em\\" height=\\"1em\\" />;"`,
)
})
it('accepts numeric values', () => {
expect(
testPlugin('<svg foo="bar" />', { width: 24, height: 24 }),
).toMatchInlineSnapshot(`"<svg foo=\\"bar\\" width={24} height={24} />;"`)
})
it('accepts string values', () => {
expect(
testPlugin('<svg foo="bar" />', { width: '2em', height: '2em' }),
).toMatchInlineSnapshot(
`"<svg foo=\\"bar\\" width=\\"2em\\" height=\\"2em\\" />;"`,
)
})
})