Skip to content

Commit

Permalink
fix(jest-each): %# is not replaced with index of the test case
Browse files Browse the repository at this point in the history
  • Loading branch information
F3n67u committed Mar 1, 2022
1 parent 7826a8f commit c40d82f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
- `[jest-config]` Pass `moduleTypes` to `ts-node` to enforce CJS when transpiling ([#12397](https://github.com/facebook/jest/pull/12397))
- `[jest-config, jest-haste-map]` Allow searching for tests in `node_modules` by exposing `retainAllFiles` ([#11084](https://github.com/facebook/jest/pull/11084))
- `[jest-core]` [**BREAKING**] Exit with status `1` if no tests are found with `--findRelatedTests` flag ([#12487](https://github.com/facebook/jest/pull/12487))
- `[jest-each]` `%#` is not replaced with index of the test case ([#12517](https://github.com/facebook/jest/pull/12517))
- `[jest-environment-jsdom]` Make `jsdom` accessible to extending environments again ([#12232](https://github.com/facebook/jest/pull/12232))
- `[jest-environment-jsdom]` Log JSDOM errors more cleanly ([#12386](https://github.com/facebook/jest/pull/12386))
- `[@jest/expect-utils]` [**BREAKING**] Fix false positives when looking for `undefined` prop ([#8923](https://github.com/facebook/jest/pull/8923))
Expand Down
46 changes: 46 additions & 0 deletions packages/jest-each/src/__tests__/array.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,52 @@ describe('jest-each', () => {
undefined,
);
});

test('calls global with title containing param values when using %#', () => {
const globalTestMocks = getGlobalTestMocks();
const eachObject = each.withGlobal(globalTestMocks)([
{name: 'foo'},
{name: 'bar'},
]);
const testFunction = get(eachObject, keyPath);
testFunction('expected index: %#', () => {});

const globalMock = get(globalTestMocks, keyPath);
expect(globalMock).toHaveBeenCalledTimes(2);
expect(globalMock).toHaveBeenCalledWith(
'expected index: 0',
expectFunction,
undefined,
);
expect(globalMock).toHaveBeenCalledWith(
'expected index: 1',
expectFunction,
undefined,
);
});

test('calls global with title containing param values when using $#', () => {
const globalTestMocks = getGlobalTestMocks();
const eachObject = each.withGlobal(globalTestMocks)([
{name: 'foo'},
{name: 'bar'},
]);
const testFunction = get(eachObject, keyPath);
testFunction('expected index: $#', () => {});

const globalMock = get(globalTestMocks, keyPath);
expect(globalMock).toHaveBeenCalledTimes(2);
expect(globalMock).toHaveBeenCalledWith(
'expected index: 0',
expectFunction,
undefined,
);
expect(globalMock).toHaveBeenCalledWith(
'expected index: 1',
expectFunction,
undefined,
);
});
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-each/src/table/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {EachTests} from '../bind';
import type {Templates} from './interpolation';
import {interpolateVariables} from './interpolation';

const SUPPORTED_PLACEHOLDERS = /%[sdifjoOp]/g;
const SUPPORTED_PLACEHOLDERS = /%[sdifjoOp#]/g;
const PRETTY_PLACEHOLDER = '%p';
const INDEX_PLACEHOLDER = '%#';
const PLACEHOLDER_PREFIX = '%';
Expand Down

0 comments on commit c40d82f

Please sign in to comment.