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

[Bug]: replacment string for index of the test case for .each is wrong in documentation #12291

Closed
essenmitsosse opened this issue Feb 2, 2022 · 5 comments · Fixed by #12517
Closed

Comments

@essenmitsosse
Copy link

Version

27.4.5

Steps to reproduce

According to the documentation:

%# - Index of the test case.
This means, this should show the index of the test case as the test name:

test.each(['a', 'b', 'c'])('%#', () => { expect(true).toBe(true); })

But it isn't working and the reason is, that the actual implementation expects $# instead of %#

Expected behavior

Either the documentation to be correct or %# to be working. Or both to preserve backwards comptability.

Actual behavior

%# is not replaced and remains as is, in the title string.

Additional context

No response

Environment

System:
    OS: macOS 12.2
    CPU: (8) x64 Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
  Binaries:
    Node: 15.14.0 - ~/.nvm/versions/node/v15.14.0/bin/node
    npm: 7.7.6 - ~/.nvm/versions/node/v15.14.0/bin/npm
  npmPackages:
    jest: ^27.1.0 => 27.4.5
@F3n67u
Copy link
Contributor

F3n67u commented Feb 27, 2022

@essenmitsosse I cannot reproduce with your snippet, could you provide a reproduced github repo?

➜  jest git:(73f3a5743b) ✗ cat ./debug/test.js                                
test.each(['a', 'b', 'c'])('%#', () => {
  expect(true).toBe(true);
});
➜  jest git:(73f3a5743b) ✗ node  ./packages/jest-cli/bin/jest.js --version
27.4.5-dev
➜  jest git:(73f3a5743b) ✗ node  ./packages/jest-cli/bin/jest.js debug/test.js
 PASS  debug/test.js
  ✓ 0 (2 ms)
  ✓ 1
  ✓ 2

Test Suites: 1 passed, 1 total
Tests:       3 passed, 3 total
Snapshots:   0 total
Time:        0.416 s, estimated 1 s
Ran all test suites matching /debug\/test.js/i.

Environment

System:
    OS: macOS 11.2.3
    CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
  Binaries:
    Node: 14.17.4 - ~/.nvm/versions/node/v14.17.4/bin/node
    Yarn: 2.4.3 - ~/.nvm/versions/node/v14.17.4/bin/yarn
    npm: 8.1.3 - ~/.nvm/versions/node/v14.17.4/bin/npm
  npmPackages:
    jest: workspace:* => 27.4.5 

@essenmitsosse
Copy link
Author

I am sorry, the test I posted, actually didn't produce the error, here is a reproduction that shows it:

test.each(['A', 'B', 'C'])(
    'This is working: %#',
    () => expect(true).toMatchSnapshot()
)
test.each([{ NAME: 'A' }, { NAME: 'B' }, { NAME: 'C' }])(
    'This is not working: %#',
    () => expect(true).toMatchSnapshot()
)

The problem only seems to occur, when test.each is passed a list of objects, instead of strings.

Reproduction Repo: essenmitsosse/jest-test-index-reproduction

@F3n67u
Copy link
Contributor

F3n67u commented Mar 1, 2022

@essenmitsosse It's fixed. thanks for your report. I am willing to help if you have any problems with this issue.

@SimenB
Copy link
Member

SimenB commented Mar 1, 2022

@github-actions
Copy link

github-actions bot commented Apr 1, 2022

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 Apr 1, 2022
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.

3 participants