tailwindcss/tests/plugins/fontSize.test.js
Adam Wathan ea10bb9d41
Add line-height modifier for font-size utilities (#9875)
* Add line-height modifier for font-size utilities

* Add test for arbitrary values

* Add failing test for non-configured modifier values

* Add more tests (including failing case)

* Remove unused code

* Add note + failing test

* Remove unused code

* Fix test

* Fix test

* Update changelog

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2022-11-22 09:37:07 -05:00

196 lines
4.5 KiB
JavaScript

import { run, html, css } from '../util/run'
test('font-size utilities can include a default line-height', () => {
let config = {
content: [{ raw: html`<div class="text-md text-sm text-lg"></div>` }],
theme: {
fontSize: {
sm: '12px',
md: ['16px', '24px'],
lg: ['20px', '28px'],
},
},
}
return run('@tailwind utilities', config).then((result) => {
expect(result.css).toMatchCss(css`
.text-md {
font-size: 16px;
line-height: 24px;
}
.text-sm {
font-size: 12px;
}
.text-lg {
font-size: 20px;
line-height: 28px;
}
`)
})
})
test('font-size utilities can include a default letter-spacing', () => {
let config = {
content: [{ raw: html`<div class="text-md text-sm text-lg"></div>` }],
theme: {
fontSize: {
sm: '12px',
md: ['16px', { letterSpacing: '-0.01em' }],
lg: ['20px', { letterSpacing: '-0.02em' }],
},
},
}
return run('@tailwind utilities', config).then((result) => {
expect(result.css).toMatchCss(css`
.text-md {
font-size: 16px;
letter-spacing: -0.01em;
}
.text-sm {
font-size: 12px;
}
.text-lg {
font-size: 20px;
letter-spacing: -0.02em;
}
`)
})
})
test('font-size utilities can include a default line-height and letter-spacing', () => {
let config = {
content: [{ raw: html`<div class="text-md text-sm text-lg"></div>` }],
theme: {
fontSize: {
sm: '12px',
md: ['16px', { lineHeight: '24px', letterSpacing: '-0.01em' }],
lg: ['20px', { lineHeight: '28px', letterSpacing: '-0.02em' }],
},
},
}
return run('@tailwind utilities', config).then((result) => {
expect(result.css).toMatchCss(css`
.text-md {
font-size: 16px;
line-height: 24px;
letter-spacing: -0.01em;
}
.text-sm {
font-size: 12px;
}
.text-lg {
font-size: 20px;
line-height: 28px;
letter-spacing: -0.02em;
}
`)
})
})
test('font-size utilities can include a font-weight', () => {
let config = {
content: [{ raw: html`<div class="text-md text-sm text-lg"></div>` }],
theme: {
fontSize: {
sm: '12px',
md: ['16px', { lineHeight: '24px', fontWeight: 500 }],
lg: ['20px', { lineHeight: '28px', fontWeight: 'bold' }],
},
},
}
return run('@tailwind utilities', config).then((result) => {
expect(result.css).toMatchCss(css`
.text-md {
font-size: 16px;
line-height: 24px;
font-weight: 500;
}
.text-sm {
font-size: 12px;
}
.text-lg {
font-size: 20px;
line-height: 28px;
font-weight: bold;
}
`)
})
})
test('font-size utilities can include a line-height modifier', () => {
let config = {
content: [
{
raw: html`<div class="text-sm md:text-base">
<div class="text-sm/6 md:text-base/7"></div>
<div class="text-sm/[21px] md:text-base/[33px]"></div>
<div class="text-[13px]/6 md:text-[19px]/8"></div>
<div class="text-[17px]/[23px] md:text-[21px]/[29px]"></div>
<div class="text-sm/999 md:text-base/000"></div>
</div>`,
},
],
theme: {
fontSize: {
sm: ['12px', '20px'],
base: ['16px', '24px'],
},
lineHeight: {
6: '24px',
7: '28px',
8: '32px',
},
},
}
return run('@tailwind utilities', config).then((result) => {
expect(result.css).toMatchCss(css`
.text-sm {
font-size: 12px;
line-height: 20px;
}
.text-sm\/6 {
font-size: 12px;
line-height: 24px;
}
.text-sm\/\[21px\] {
font-size: 12px;
line-height: 21px;
}
.text-\[13px\]\/6 {
font-size: 13px;
line-height: 24px;
}
.text-\[17px\]\/\[23px\] {
font-size: 17px;
line-height: 23px;
}
@media (min-width: 768px) {
.md\:text-base {
font-size: 16px;
line-height: 24px;
}
.md\:text-base\/7 {
font-size: 16px;
line-height: 28px;
}
.md\:text-base\/\[33px\] {
font-size: 16px;
line-height: 33px;
}
.md\:text-\[19px\]\/8 {
font-size: 19px;
line-height: 32px;
}
.md\:text-\[21px\]\/\[29px\] {
font-size: 21px;
line-height: 29px;
}
}
`)
})
})