/
githubmirror
/
30-seconds-of-code
Обзор
Документация
Войти
/
githubmirror
/
30-seconds-of-code
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
spec/lib/stringUtils.test.js
96 строк
3 KB
Angelos Chalaris
Simplify imports
05 авг 2024, 13:25
Не верифицирован
05 авг 2024, 13:25
013ae41
Код
Авторство
О чём код?
import { describe, it, expect } from 'vitest'; import StringUtils from '#src/lib/stringUtils.js'; describe('StringUtils', () => { describe('capitalize', () => { it('should capitalize the first letter of a string', () => { expect(StringUtils.capitalize('hello')).toBe('Hello'); }); it('should capitalize the first letter and lowercase the rest of a string', () => { expect(StringUtils.capitalize('hello', true)).toBe('Hello'); }); }); describe('toKebabCase', () => { it('should convert a string to kebab case', () => { expect(StringUtils.toKebabCase('Hello World')).toBe('hello-world'); }); }); describe('convertToValidId', () => { it('should convert a string to a valid id name', () => { const htmlString = '<p>This is a <strong>paragraph</strong>.</p>'; const validId = 'this-is-a-paragraph'; expect(StringUtils.convertToValidId(htmlString)).toBe(validId); }); }); describe('convertToSeoSlug', () => { it('should convert a string to a SEO slug', () => { expect(StringUtils.convertToSeoSlug('Hello World')).toBe('/hello-world'); }); }); describe('stripMarkdownFormat', () => { const markdownString = 'This is `code` and this is **bold** and this is [a link](https://example.com) and this is _italic_.'; const strippedString = 'This is code and this is bold and this is a link and this is italic.'; it('should strip markdown format from a string', () => { expect(StringUtils.stripMarkdown(markdownString)).toBe(strippedString); }); }); describe('stripHtmlParagraphsAndLinks', () => { it('should strip HTML paragraphs and links', () => { expect( StringUtils.stripHtmlParagraphsAndLinks( '<p><a href="http://example.com">Hello</a></p>' ) ).toBe('Hello'); }); }); describe('stripHtmlTags', () => { const htmlString = '<p>This is a <strong>paragraph</strong>.</p>'; const strippedString = 'This is a paragraph.'; it('should strip HTML tags from a string', () => { expect(StringUtils.stripHtmlTags(htmlString)).toBe(strippedString); }); }); describe('stripHtml', () => { it('should strip HTML', () => { expect(StringUtils.stripHtml('<p>Hello & hi!</p>')).toBe( 'Hello & hi!' ); }); }); describe('normalizedTokens', () => { it('should normalize tokens', () => { expect(StringUtils.normalizedTokens('Hello a World!')).toEqual([ 'hello', 'world', ]); }); }); describe('escapeHtml', () => { it('should escape HTML', () => { expect(StringUtils.escapeHtml('Hello & "world"')).toBe( 'Hello & "world"' ); }); }); describe('formatTag', () => { it('should format a tag', () => { expect(StringUtils.formatTag('hello')).toBe('Hello'); }); }); });