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

Test arguments are skipped during title parameter injection #8286

Closed
krizalys opened this issue Apr 8, 2019 · 3 comments · Fixed by #8289
Closed

Test arguments are skipped during title parameter injection #8286

krizalys opened this issue Apr 8, 2019 · 3 comments · Fixed by #8289

Comments

@krizalys
Copy link

krizalys commented Apr 8, 2019

🐛 Bug Report

In some cases, test arguments are skipped during title parameter injection.

To Reproduce

Consider the following Jest test:

class MyClass {
  constructor(value) {
    this.value = value
  }
}

describe("Test arguments are skipped during title parameter injection", () => {
  test.each([
    ["%d", new Object("My object")]
  ])("given \"%s\", returns %p", () => {
  })
})

Running it produces:

 PASS  test/unit/TestArgsSkipped.test.js
  Test arguments are skipped during title parameter injection
    ✓ given "NaN", returns %p

The title parameters have not been substituted as expected. The first one, %s, has been substituted by the (non-)number NaN, suggesting some confusion with the actual injected value of %d, and the second one, %p has not subtituted at all.

From what I observed, two conditions must be met at the same time for this to happen:

  • Having test arguments looking like parameter placeholder themselves: %d in my example
  • Having certain object arguments - does seem to happen with all prototypes, perhaps the presence of a toString function matters

Expected behavior

 PASS  test/unit/TestArgsSkipped.test.js
  Test arguments are skipped during title parameter injection
    ✓ given "%d", returns {"value": "My object"} (1ms)

Link to repl or repo (highly encouraged)

Cannot provide this, since test.each seems to have been introduced in Jest 23, whereas repl.it is currently using Jest 22.

Run npx envinfo --preset jest

Paste the results here:

npx: installed 1 in 0.737s

  System:
    OS: Linux 5.0 Arch Linux
    CPU: (8) x64 Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz
  Binaries:
    Node: 11.13.0 - /usr/bin/node
    npm: 6.9.0 - /usr/bin/npm
  npmPackages:
    jest: ^24.7.1 => 24.7.1 
@SimenB
Copy link
Member

SimenB commented Apr 8, 2019

/cc @mattphillips

@mattphillips
Copy link
Contributor

@krizalys yup seems to be a bug nice catch! I've opened up a PR with a fix 😄

@github-actions
Copy link

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 May 12, 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.

3 participants