[READ-ONLY] a fast, modern browser for the npm registry
at main 38 lines 1.1 kB view raw
1import { describe, expect, it } from 'vitest' 2import { decodeHtmlEntities, toIsoDateString } from '../../../../app/utils/formatters' 3 4describe('toIsoDateString', () => { 5 it('formats a date as YYYY-MM-DD', () => { 6 expect(toIsoDateString(new Date('2024-03-15T00:00:00Z'))).toBe('2024-03-15') 7 }) 8 9 it('pads single-digit month and day', () => { 10 expect(toIsoDateString(new Date('2024-01-05T00:00:00Z'))).toBe('2024-01-05') 11 }) 12}) 13 14describe('decodeHtmlEntities', () => { 15 it.each([ 16 ['&amp;', '&'], 17 ['&lt;', '<'], 18 ['&gt;', '>'], 19 ['&quot;', '"'], 20 ['&#39;', "'"], 21 ['&apos;', "'"], 22 ['&nbsp;', ' '], 23 ] as const)('%s → %s', (input, expected) => { 24 expect(decodeHtmlEntities(input)).toBe(expected) 25 }) 26 27 it('decodes multiple entities in one string', () => { 28 expect(decodeHtmlEntities('a &amp; b &lt; c')).toBe('a & b < c') 29 }) 30 31 it('leaves plain text unchanged', () => { 32 expect(decodeHtmlEntities('say no to bloat')).toBe('say no to bloat') 33 }) 34 35 it('leaves unknown entities unchanged', () => { 36 expect(decodeHtmlEntities('&unknown;')).toBe('&unknown;') 37 }) 38})