Printf formatting not working as expected - possible bug?
See original GitHub issueDescribe the bug
The printf
formatting isn’t working as expected from the example in the documentation.
describe.each([
{ a: 1, b: 1, expected: 2 },
{ a: 1, b: 2, expected: 3 },
{ a: 2, b: 1, expected: 3 },
])('describe object add(%i, %i)', ({ a, b, expected }) => {
test(`returns ${expected}`, () => {
expect(a + b).toBe(expected)
})
})
I would expect to get
describe object add(1, 1)
returns 2
describe object add(1, 2)
returns 3
describe object add(2, 1)
returns 3
Reproduction
Run the example code.
You will get output:

System Info
Node: v16.5.0
Vite: 2.9.1
Vitest: 0.9.3
Used Package Manager
pnpm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created a year ago
- Comments:13 (6 by maintainers)
Top Results From Across the Web
printf() seemingly not working as expected - Stack Overflow
You are either missing a newline at the end of the printf format string, or another call to fflush. example why fflush is...
Read more >Bash printf formating not working - Unix & Linux Stack Exchange
printf '%b\n' 'ABC\ctest' has a well specified behaviour. The \c causes everything remaining (including the newline in the format string) to be ...
Read more >68052 – No printf format warnings in C++ code for macro in ...
Since that macro is from a system header, the printf format error is attributed to the system header, and no diagnostic is generated....
Read more >sprintf - Manual - PHP
The order of the placeholders in the format string does not match the order ... being shown printf, but it should say sprintf,...
Read more >Solved: Simple printf formatting not working - NXP Community
I building a simple project to develop some interface code. I'm using printf to send data to the debug console for verification of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@ooohmydawn the documentation has been updated with a working example in https://github.com/vitest-dev/vitest/pull/1368
The right syntax is
add($a, $b)
instead ofadd(%i, %i)
, see https://vitest.dev/api/#describe-eachThis does not seem to handle complex data formats: https://github.com/vitest-dev/vitest/blob/f8db7d7346c3ff3650bf450f5eba93b0dd8e73ff/packages/vitest/src/runtime/suite.ts#L28-L31