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 Feb 28, 2022
1 parent 7826a8f commit 63e8fd1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
46 changes: 46 additions & 0 deletions packages/jest-each/src/__tests__/array.test.ts
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 string: %#', () => {});

const globalMock = get(globalTestMocks, keyPath);
expect(globalMock).toHaveBeenCalledTimes(2);
expect(globalMock).toHaveBeenCalledWith(
'expected string: foo 0',
expectFunction,
undefined,
);
expect(globalMock).toHaveBeenCalledWith(
'expected string: bar 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 string: $#', () => {});

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

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-each/src/table/array.ts
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 63e8fd1

Please sign in to comment.