main
js 51 lines 1.39 KB
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @emails react-core
8 */
9
10 'use strict';
11
12 let normalizeConsoleFormat;
13
14 describe('normalizeConsoleFormat', () => {
15 beforeEach(() => {
16 normalizeConsoleFormat = require('shared/normalizeConsoleFormat').default;
17 });
18
19 it('normalize empty string', async () => {
20 expect(normalizeConsoleFormat('', [1, {}, 'foo'], 0)).toMatchInlineSnapshot(
21 `"%o %o %s"`,
22 );
23 });
24
25 it('normalize extra args', async () => {
26 expect(
27 normalizeConsoleFormat('%f', [1, {}, 'foo'], 0),
28 ).toMatchInlineSnapshot(`"%f %o %s"`);
29 });
30
31 it('normalize fewer than args', async () => {
32 expect(
33 normalizeConsoleFormat('%s %O %o %f', [1, {}, 'foo'], 0),
34 ).toMatchInlineSnapshot(`"%s %O %o %%f"`);
35 });
36
37 it('normalize escape sequences', async () => {
38 expect(
39 normalizeConsoleFormat('hel%lo %s %%s world', [1, 'foo'], 0),
40 ).toMatchInlineSnapshot(`"hel%lo %s %%s world %s"`);
41 });
42
43 it('normalize ending with escape', async () => {
44 expect(
45 normalizeConsoleFormat('hello %s world %', [1, {}, 'foo'], 0),
46 ).toMatchInlineSnapshot(`"hello %s world % %o %s"`);
47 expect(
48 normalizeConsoleFormat('hello %s world %', [], 0),
49 ).toMatchInlineSnapshot(`"hello %%s world %"`);
50 });
51 });