Skip to content

Commit e4a796d

Browse files
authored
fix(jest-each): %# is not replaced with index of the test case (#12517)
1 parent 4067c51 commit e4a796d

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
- `[jest-config]` Pass `moduleTypes` to `ts-node` to enforce CJS when transpiling ([#12397](https://github.com/facebook/jest/pull/12397))
4949
- `[jest-config, jest-haste-map]` Allow searching for tests in `node_modules` by exposing `retainAllFiles` ([#11084](https://github.com/facebook/jest/pull/11084))
5050
- `[jest-core]` [**BREAKING**] Exit with status `1` if no tests are found with `--findRelatedTests` flag ([#12487](https://github.com/facebook/jest/pull/12487))
51+
- `[jest-each]` `%#` is not replaced with index of the test case ([#12517](https://github.com/facebook/jest/pull/12517))
5152
- `[jest-environment-jsdom]` Make `jsdom` accessible to extending environments again ([#12232](https://github.com/facebook/jest/pull/12232))
5253
- `[jest-environment-jsdom]` Log JSDOM errors more cleanly ([#12386](https://github.com/facebook/jest/pull/12386))
5354
- `[@jest/expect-utils]` [**BREAKING**] Fix false positives when looking for `undefined` prop ([#8923](https://github.com/facebook/jest/pull/8923))

packages/jest-each/src/__tests__/array.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,52 @@ describe('jest-each', () => {
368368
undefined,
369369
);
370370
});
371+
372+
test('calls global with title containing param values when using %#', () => {
373+
const globalTestMocks = getGlobalTestMocks();
374+
const eachObject = each.withGlobal(globalTestMocks)([
375+
{name: 'foo'},
376+
{name: 'bar'},
377+
]);
378+
const testFunction = get(eachObject, keyPath);
379+
testFunction('expected index: %#', () => {});
380+
381+
const globalMock = get(globalTestMocks, keyPath);
382+
expect(globalMock).toHaveBeenCalledTimes(2);
383+
expect(globalMock).toHaveBeenCalledWith(
384+
'expected index: 0',
385+
expectFunction,
386+
undefined,
387+
);
388+
expect(globalMock).toHaveBeenCalledWith(
389+
'expected index: 1',
390+
expectFunction,
391+
undefined,
392+
);
393+
});
394+
395+
test('calls global with title containing param values when using $#', () => {
396+
const globalTestMocks = getGlobalTestMocks();
397+
const eachObject = each.withGlobal(globalTestMocks)([
398+
{name: 'foo'},
399+
{name: 'bar'},
400+
]);
401+
const testFunction = get(eachObject, keyPath);
402+
testFunction('expected index: $#', () => {});
403+
404+
const globalMock = get(globalTestMocks, keyPath);
405+
expect(globalMock).toHaveBeenCalledTimes(2);
406+
expect(globalMock).toHaveBeenCalledWith(
407+
'expected index: 0',
408+
expectFunction,
409+
undefined,
410+
);
411+
expect(globalMock).toHaveBeenCalledWith(
412+
'expected index: 1',
413+
expectFunction,
414+
undefined,
415+
);
416+
});
371417
});
372418
});
373419

packages/jest-each/src/table/array.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {EachTests} from '../bind';
1313
import type {Templates} from './interpolation';
1414
import {interpolateVariables} from './interpolation';
1515

16-
const SUPPORTED_PLACEHOLDERS = /%[sdifjoOp]/g;
16+
const SUPPORTED_PLACEHOLDERS = /%[sdifjoOp#]/g;
1717
const PRETTY_PLACEHOLDER = '%p';
1818
const INDEX_PLACEHOLDER = '%#';
1919
const PLACEHOLDER_PREFIX = '%';

0 commit comments

Comments
 (0)