/
vasya2
/
var2
Обзор
Документация
Войти
/
vasya2
/
var2
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
client/src/utils/format.test.ts
45 строк
2 KB
Oliver Eyton-Williams
chore: upgrade eslint (#58575)
07 фев 2025, 23:48
Не верифицирован
07 фев 2025, 23:48
6e9513a
Код
Авторство
О чём код?
import { format } from './format'; function simpleFun() { // eslint-disable-next-line no-var, @typescript-eslint/no-unused-vars var x = 'y'; } /* format uses util.inspect to do almost everything, the tests are just there to warn us if util.inspect ever changes */ describe('format', () => { it('returns a string', () => { expect(typeof format('')).toBe('string'); expect(typeof format({})).toBe('string'); expect(typeof format([])).toBe('string'); }); it('does not modify strings', () => { expect(format('')).toBe(''); expect(format('abcde')).toBe('abcde'); expect(format('Case Sensitive')).toBe('Case Sensitive'); }); it('formats shallow objects nicely', () => { expect(format({})).toBe('{}'); expect(format({ a: 'one', b: 'two' })).toBe(`{ a: 'one', b: 'two' }`); }); it('formats functions the same way as console.log', () => { expect(format(simpleFun)).toBe('[Function: simpleFun]'); }); it('recurses into arrays', () => { const objsInArr = [{ a: 'one' }, 'b', simpleFun]; expect(format(objsInArr)).toBe( `[ { a: 'one' }, 'b', [Function: simpleFun] ]` ); }); it('handles all primitive values', () => { const primitives = ['str', 57, true, false, null, undefined]; expect(format(primitives)).toBe( `[ 'str', 57, true, false, null, undefined ]` ); expect(format(BigInt(10))).toBe(`10n`); expect(format(Symbol('Sym'))).toBe(`Symbol(Sym)`); }); it(`outputs NaN as 'NaN'`, () => { expect(format(NaN)).toBe('NaN'); }); });