mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-29 18:13:47 +00:00
test: подключить vitest и покрыть утилиты юнит-тестами
This commit is contained in:
28
src/utils/sanitizeSurrogates.test.ts
Normal file
28
src/utils/sanitizeSurrogates.test.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { sanitizeSurrogates } from './sanitizeSurrogates';
|
||||
|
||||
describe('sanitizeSurrogates', () => {
|
||||
it('returns surrogate-free strings unchanged', () => {
|
||||
expect(sanitizeSurrogates('')).toBe('');
|
||||
expect(sanitizeSurrogates('https://host/sub/uuid#remark')).toBe('https://host/sub/uuid#remark');
|
||||
});
|
||||
|
||||
it('keeps valid surrogate pairs intact', () => {
|
||||
expect(sanitizeSurrogates('server 😀 name')).toBe('server 😀 name');
|
||||
});
|
||||
|
||||
it('replaces a lone high surrogate', () => {
|
||||
expect(sanitizeSurrogates('abc\uD83D')).toBe('abc<62>');
|
||||
expect(sanitizeSurrogates('\uD83Dxyz')).toBe('<27>xyz');
|
||||
});
|
||||
|
||||
it('replaces a lone low surrogate', () => {
|
||||
expect(sanitizeSurrogates('abc\uDE00def')).toBe('abc<62>def');
|
||||
});
|
||||
|
||||
it('makes a truncated-emoji string safe for encodeURI', () => {
|
||||
const broken = 'remark \uD83D truncated';
|
||||
expect(() => encodeURI(broken)).toThrow();
|
||||
expect(() => encodeURI(sanitizeSurrogates(broken))).not.toThrow();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user