tailwindcss/tests/plugins/fontFamily.test.js
Robin Malfait dba5043591
Ensure all built-in plugins have tests (#11618)
* move `preflight` tests to `plugins` test folder

* move `container` tests to `plugins` test folder

* add a test that ensures that all built-in plugins have tests

This is based on a few assumptions:

1. All plugins exist in the `corePlugins.js` file and are exported as
   `corePlugins`
2. Each exported plugin in that object has a file with a corresponding
   name in the current (`tests/plugins/`) folder

* add dedicated plugin tests in the `plugins` folder

* add a test that ensures that all built-in variant plugins have tests

This is based on a few assumptions:

1. All variant plugins exist in the `corePlugins.js` file and are
   exported as `variantPlugins`
2. Each exported plugin in that object has a file with a corresponding
   name in the current (`tests/plugins/variants/`) folder

* add dedicated variant plugin tests in the `plugins/variants` folder

* cleanup basic usage test

* move existing animation tests to animation plugin tests

* move `apply-important-selector` tests to more appropriate location
2023-07-24 11:41:52 +02:00

153 lines
4.1 KiB
JavaScript

import { run, html, css, quickPluginTest } from '../util/run'
quickPluginTest('fontFamily').toMatchFormattedCss(css`
.font-mono {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New,
monospace;
}
.font-sans {
font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto,
Helvetica Neue, Arial, Noto Sans, sans-serif, Apple Color Emoji, Segoe UI Emoji,
Segoe UI Symbol, Noto Color Emoji;
}
.font-serif {
font-family: ui-serif, Georgia, Cambria, Times New Roman, Times, serif;
}
`)
test('font-family utilities can be defined as a string', () => {
let config = {
content: [{ raw: html`<div class="font-sans"></div>` }],
theme: {
fontFamily: {
sans: 'Helvetica, Arial, sans-serif',
},
},
}
return run('@tailwind utilities', config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.font-sans {
font-family: Helvetica, Arial, sans-serif;
}
`)
})
})
test('font-family utilities can be defined as an array', () => {
let config = {
content: [{ raw: html`<div class="font-sans"></div>` }],
theme: {
fontFamily: {
sans: ['Helvetica', 'Arial', 'sans-serif'],
},
},
}
return run('@tailwind utilities', config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.font-sans {
font-family: Helvetica, Arial, sans-serif;
}
`)
})
})
test('font-family values are not automatically escaped', () => {
let config = {
content: [{ raw: html`<div class="font-sans"></div>` }],
theme: {
fontFamily: {
sans: ["'Exo 2'", 'sans-serif'],
},
},
}
return run('@tailwind utilities', config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.font-sans {
font-family: 'Exo 2', sans-serif;
}
`)
})
})
test('font-feature-settings can be provided when families are defined as a string', () => {
let config = {
content: [{ raw: html`<div class="font-sans"></div>` }],
theme: {
fontFamily: {
sans: ['Helvetica, Arial, sans-serif', { fontFeatureSettings: '"cv11", "ss01"' }],
},
},
}
return run('@tailwind utilities', config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.font-sans {
font-feature-settings: 'cv11', 'ss01';
font-family: Helvetica, Arial, sans-serif;
}
`)
})
})
test('font-feature-settings can be provided when families are defined as an array', () => {
let config = {
content: [{ raw: html`<div class="font-sans"></div>` }],
theme: {
fontFamily: {
sans: [['Helvetica', 'Arial', 'sans-serif'], { fontFeatureSettings: '"cv11", "ss01"' }],
},
},
}
return run('@tailwind utilities', config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.font-sans {
font-feature-settings: 'cv11', 'ss01';
font-family: Helvetica, Arial, sans-serif;
}
`)
})
})
test('font-variation-settings can be provided when families are defined as a string', () => {
let config = {
content: [{ raw: html`<div class="font-sans"></div>` }],
theme: {
fontFamily: {
sans: ['Inter, sans-serif', { fontVariationSettings: '"opsz" 32' }],
},
},
}
return run('@tailwind utilities', config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.font-sans {
font-variation-settings: 'opsz' 32;
font-family: Inter, sans-serif;
}
`)
})
})
test('font-variation-settings can be provided when families are defined as an array', () => {
let config = {
content: [{ raw: html`<div class="font-sans"></div>` }],
theme: {
fontFamily: {
sans: [['Inter', 'sans-serif'], { fontVariationSettings: '"opsz" 32' }],
},
},
}
return run('@tailwind utilities', config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.font-sans {
font-variation-settings: 'opsz' 32;
font-family: Inter, sans-serif;
}
`)
})
})