Testing Text Truncation Utilities in GatsbyJS
This test suite validates the text truncation utility functions in the Gatsby preload fonts plugin. It specifically focuses on the ellipses function behavior, ensuring proper text handling and truncation with ellipsis.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
gatsbyjs/gatsby
packages/gatsby-plugin-preload-fonts/src/__tests__/utils.test.js
const { ellipses } = require(`../prepare/utils`)
describe(`utils`, () => {
describe(`ellipses`, () => {
it(`does nothing to text under max length`, () => {
expect(ellipses(`some text`, 10)).toBe(`some text`)
})
it(`does nothing to text at max length`, () => {
expect(ellipses(`some text`, 9)).toBe(`some text`)
})
it(`truncates text over max length with \`...\``, () => {
expect(ellipses(`some text`, 4)).toBe(`some...`)
})
})
})