diff --git a/packages/jest-each/src/__tests__/array.test.ts b/packages/jest-each/src/__tests__/array.test.ts index 7bd21be8e52d..f496747524b0 100644 --- a/packages/jest-each/src/__tests__/array.test.ts +++ b/packages/jest-each/src/__tests__/array.test.ts @@ -144,7 +144,7 @@ describe('jest-each', () => { ]); const testFunction = get(eachObject, keyPath); testFunction( - 'expected string: %% %%s %s %d %s %s %d %j %s %j %d %d %#', + 'expected string: %% %%s %s %d %s %s %d %j %s %j %d %d %# %$', noop, ); @@ -153,14 +153,14 @@ describe('jest-each', () => { expect(globalMock).toHaveBeenCalledWith( `expected string: % %s hello 1 null undefined 1.2 ${JSON.stringify({ foo: 'bar', - })} () => {} [] Infinity NaN 0`, + })} () => {} [] Infinity NaN 0 1`, expectFunction, undefined, ); expect(globalMock).toHaveBeenCalledWith( `expected string: % %s world 1 null undefined 1.2 ${JSON.stringify({ baz: 'qux', - })} () => {} [] Infinity NaN 1`, + })} () => {} [] Infinity NaN 1 2`, expectFunction, undefined, ); diff --git a/packages/jest-each/src/table/array.ts b/packages/jest-each/src/table/array.ts index 1b1101c26a37..86ddb8470fff 100644 --- a/packages/jest-each/src/table/array.ts +++ b/packages/jest-each/src/table/array.ts @@ -15,6 +15,7 @@ import {type Templates, interpolateVariables} from './interpolation'; const SUPPORTED_PLACEHOLDERS = /%[sdifjoOp#]/g; const PRETTY_PLACEHOLDER = '%p'; const INDEX_PLACEHOLDER = '%#'; +const NUMBER_PLACEHOLDER = '%$'; const PLACEHOLDER_PREFIX = '%'; const ESCAPED_PLACEHOLDER_PREFIX = /%%/g; const JEST_EACH_PLACEHOLDER_ESCAPE = '@@__JEST_EACH_PLACEHOLDER_ESCAPE__@@'; @@ -71,7 +72,10 @@ const formatTitle = ( return util.format(formattedTitle, normalisedValue); }, - interpolateTitleIndex(interpolateEscapedPlaceholders(title), rowIndex), + interpolateTitleIndexAndNumber( + interpolateEscapedPlaceholders(title), + rowIndex, + ), ) .replace(new RegExp(JEST_EACH_PLACEHOLDER_ESCAPE, 'g'), PLACEHOLDER_PREFIX); @@ -89,8 +93,10 @@ const getMatchingPlaceholders = (title: string) => const interpolateEscapedPlaceholders = (title: string) => title.replace(ESCAPED_PLACEHOLDER_PREFIX, JEST_EACH_PLACEHOLDER_ESCAPE); -const interpolateTitleIndex = (title: string, index: number) => - title.replace(INDEX_PLACEHOLDER, index.toString()); +const interpolateTitleIndexAndNumber = (title: string, index: number) => + title + .replace(INDEX_PLACEHOLDER, index.toString()) + .replace(NUMBER_PLACEHOLDER, (index + 1).toString()); const interpolatePrettyPlaceholder = (title: string, value: unknown) => title.replace(PRETTY_PLACEHOLDER, pretty(value, {maxDepth: 1, min: true}));