Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong interpolation in test.each when the value of array contains multiple % #11363

Closed
frozenbonito opened this issue Apr 30, 2021 · 1 comment · Fixed by #11364
Closed

Wrong interpolation in test.each when the value of array contains multiple % #11363

frozenbonito opened this issue Apr 30, 2021 · 1 comment · Fixed by #11364

Comments

@frozenbonito
Copy link
Contributor

🐛 Bug Report

When the value of array contains multiple %, wrong interpolation may occur.

To Reproduce

index.text.js

describe("test name should to be `%d %d`", () => {
  test.each([["%d %d", 1, 2, 3]])("%s", (_, a, b, expected) => {
    expect(a + b).toBe(expected);
  });
});

describe("test name should to be `%%d`", () => {
  test.each([["%%d", 1, 2, 3]])("%s", (_, a, b, expected) => {
    expect(a + b).toBe(expected);
  });
});

Run npx jest, then you can see the following:

$ npx jest
 PASS  ./index.test.js
  test name should to be `%d %d`
    ✓ %d 1 (2 ms)
  test name should to be `%%d`
    ✓ %1

Test Suites: 1 passed, 1 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        0.324 s, estimated 1 s
Ran all test suites.

Expected behavior

$ npx jest
 PASS  ./index.test.js
  test name should to be `%d %d`
    ✓ %d %d (2 ms)
  test name should to be `%%d`
    ✓ %%d

Test Suites: 1 passed, 1 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        0.324 s, estimated 1 s
Ran all test suites.

Link to repl or repo (highly encouraged)

envinfo

  System:
    OS: Linux 4.19 Debian GNU/Linux 10 (buster) 10 (buster)
    CPU: (8) x64 Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz
  Binaries:
    Node: 14.16.1 - ~/.nvm/versions/node/v14.16.1/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v14.16.1/bin/yarn
    npm: 7.11.1 - ~/.nvm/versions/node/v14.16.1/bin/npm
  npmPackages:
    jest: ^26.6.3 => 26.6.3
@github-actions
Copy link

github-actions bot commented Jun 1, 2021

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant