mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-02-28 05:01:24 -05:00
* rename js files to ts * start migrating ajax * finish migrating ajax * migrate algolia-locale-setup * migrate format * migrate format.test * migrate get-words * install axios for types in handled-error * migrate handled-error * migrate handled-error.test * migrate report-error * migrate script-loaders * migrate to-learn-path * correct renamed imports * remove unnecessary type assertions in searchBar * remove unnecessary global comment * remove unnecessary max-len enable/disable * change axios imports to type imports * revert to .then() from await * use UserType from redux/prop-types * replace assertion with generic type * revert format to JS * remove unused getArticleById() * update putUpdateUserFlag() to use Record * remove unnecessary envData cast * update algolia-locale-setup types * remove invalid key property
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
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,
|
|
BigInt(10),
|
|
true,
|
|
false,
|
|
null,
|
|
// eslint-disable-next-line no-undefined
|
|
undefined,
|
|
Symbol('Sym')
|
|
];
|
|
expect(format(primitives)).toBe(
|
|
`[ 'str', 57, 10n, true, false, null, undefined, Symbol(Sym) ]`
|
|
);
|
|
});
|
|
it(`outputs NaN as 'NaN'`, () => {
|
|
expect(format(NaN)).toBe('NaN');
|
|
});
|
|
});
|