File size: 1,902 Bytes
1e92f2d |
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 |
import { validateLocalFontFunctionCall } from './validate-local-font-function-call'
describe('validateLocalFontFunctionCall', () => {
test('Not using default export', async () => {
expect(() =>
validateLocalFontFunctionCall('Named', {})
).toThrowErrorMatchingInlineSnapshot(
`"next/font/local has no named exports"`
)
})
test('Missing src', async () => {
expect(() =>
validateLocalFontFunctionCall('', {})
).toThrowErrorMatchingInlineSnapshot(`"Missing required \`src\` property"`)
})
test('Invalid file extension', async () => {
expect(() =>
validateLocalFontFunctionCall('', { src: './font/font-file.abc' })
).toThrowErrorMatchingInlineSnapshot(
`"Unexpected file \`./font/font-file.abc\`"`
)
})
test('Invalid display value', async () => {
expect(() =>
validateLocalFontFunctionCall('', {
src: './font-file.woff2',
display: 'invalid',
})
).toThrowErrorMatchingInlineSnapshot(`
"Invalid display value \`invalid\`.
Available display values: \`auto\`, \`block\`, \`swap\`, \`fallback\`, \`optional\`"
`)
})
test('Invalid declaration', async () => {
expect(() =>
validateLocalFontFunctionCall('', {
src: './font-file.woff2',
declarations: [{ prop: 'src', value: '/hello.woff2' }],
})
).toThrowErrorMatchingInlineSnapshot(`"Invalid declaration prop: \`src\`"`)
})
test('Valid font-family declaration', async () => {
expect(() =>
validateLocalFontFunctionCall('', {
src: './font-file.woff2',
declarations: [{ prop: 'font-family', value: 'MyCustomFont' }],
})
).not.toThrow()
})
test('Empty src array', async () => {
expect(() =>
validateLocalFontFunctionCall('', {
src: [],
})
).toThrowErrorMatchingInlineSnapshot(`"Unexpected empty \`src\` array."`)
})
})
|