Skip to content

Commit

Permalink
fix(jest-each): fix wrong interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
frozenbonito committed May 1, 2021
1 parent c7ce1c3 commit 0821281
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 7 additions & 1 deletion packages/jest-each/src/__tests__/array.test.ts
Expand Up @@ -403,12 +403,13 @@ describe('jest-each', () => {
const eachObject = each.withGlobal(globalTestMocks)([
['hello', '%d', 10, '%s', {foo: 'bar'}],
['world', '%i', 1991, '%p', {foo: 'bar'}],
['joe', '%d %d', 10, '%%s', {foo: 'bar'}],
]);
const testFunction = get(eachObject, keyPath);
testFunction('expected string: %s %s %d %s %p', () => {});

const globalMock = get(globalTestMocks, keyPath);
expect(globalMock).toHaveBeenCalledTimes(2);
expect(globalMock).toHaveBeenCalledTimes(3);
expect(globalMock).toHaveBeenCalledWith(
'expected string: hello %d 10 %s {"foo": "bar"}',
expectFunction,
Expand All @@ -419,6 +420,11 @@ describe('jest-each', () => {
expectFunction,
undefined,
);
expect(globalMock).toHaveBeenCalledWith(
'expected string: joe %d %d 10 %%s {"foo": "bar"}',
expectFunction,
undefined,
);
});
});
});
Expand Down
7 changes: 5 additions & 2 deletions packages/jest-each/src/table/array.ts
Expand Up @@ -51,8 +51,11 @@ const formatTitle = (
.replace(new RegExp(JEST_EACH_PLACEHOLDER_ESCAPE, 'g'), PLACEHOLDER_PREFIX);

const normalisePlaceholderValue = (value: unknown) =>
typeof value === 'string' && SUPPORTED_PLACEHOLDERS.test(value)
? value.replace(PLACEHOLDER_PREFIX, JEST_EACH_PLACEHOLDER_ESCAPE)
typeof value === 'string'
? value.replace(
new RegExp(PLACEHOLDER_PREFIX, 'g'),
JEST_EACH_PLACEHOLDER_ESCAPE,
)
: value;

const getMatchingPlaceholders = (title: string) =>
Expand Down

0 comments on commit 0821281

Please sign in to comment.