Vscode-jest: Add full support for parametrized tests

Created on 25 Feb 2019  ·  12Comments  ·  Source: jest-community/vscode-jest

Environment

  1. node -v: v11.10.0
  2. npm -v: 6.7.0
  3. npm ls jest: └── [email protected]
  4. Operating system: macOS Mojave

Prerequisite

  • are you able to run jest test from command line? yes
  • how do you run your tests from command line? (for example: npm run test or node_modules/.bin/jest) npm test

Expected Behavior

When using syntax test.each(table)(name, fn, timeout) described here test status circles show the status of tests and failed test error appears in-line.

Actual Behavior

When using syntax test.each(table)(name, fn, timeout) test status circles are not shown and test errors are not displayed inline.

Workaround

If applying parametrization to describe with describe.each, test status information seems to be showed correctly.

In the image below all three tests should have been marked as failed. As it can be seen, the second does not show any test status information and the third (workaround) seems to work. Since I don't want to wrap all my separate tests into describe.each workaround is not that useful in my case.

screenshot 2019-02-25 at 10 34 51

Most helpful comment

Upvote

All 12 comments

Was just looking for the same thing. it.each/test.each does not work, but it would be really helpful if it would. To use describe.each instead is not an applicable workaround for me as it defeats the purpose of having several things to test for one describe.

Upvote

Upvote and bump 👍

upvote

for people who are interested in this issue, please try v4-alpha that should have addressed this issue.

@connectdotz , I'm using vscode-jest-4.0.0-alpha.2.

it seams when there is only one it.each per describe the status is displayed correctly, when two or more the status is ?.

  1. node -v: v14.15.4
  2. npm -v: 6.14.11
  3. npm ls jest or npm ls react-scripts (if you haven’t ejected): [email protected]
  4. your vscode-jest settings if customized:

    • jest.pathToJest? not customized

    • jest.pathToConfig? not customized

  5. OS: Ubuntu 20.04 (64 bit).
  6. Jest Config:
{
    "preset": "ts-jest",
    "testEnvironment": "node",
    "collectCoverage": true,
    "collectCoverageFrom": [
      "src/**/*.ts"
    ]
  }

Screenshot from 2021-01-15 13-12-52
Screenshot from 2021-01-15 13-14-16
Screenshot from 2021-01-15 13-25-05

describe('id', () => {
  it.each([
    [true],
    [false],
  ])('returns %s for %s', value => {
    expect(value).toBe(value);
  });
});
describe('not', () => {
  it.each([
    [true],
    [false],
  ])('%s not equal to reverse', value => {
    expect(!value).not.toBe(value);
  });
});

indeed we have some gaps to cover... see #649

v4.0.0-alpha.3 is released today. The main change is to support the parameterized tests. Feel free to give this release a try and open new issues if needed...

v4.0.0-alpha.3 is released today. The main change is to support the parameterized tests. Feel free to give this release a try and open new issues if needed...

I will try it today some later. Thanks a lot for a quick fix!

@connectdotz , hey

Now correctly works only the first in the file it.each:

Screenshot from 2021-01-27 21-20-33

And I guess the number of test-cases is displayed for whole file.

@DScheglov I tried your snippet above and all seems to be fine:

Screen Shot 2021-01-27 at 4 45 30 PM

Something else is at play here... which jest version your project is on? I should have mentioned that for parameterized tests to be properly reported, you need to have jest version >= 26.5.0 (see migration notes for alpha.3 release). Otherwise, can you post the relevant debug message from the developer console or OUTPUT channel?

@DScheglov I tried your snippet above and all seems to be fine:
Something else is at play here... which jest version your project is on? I should have mentioned that for parameterized tests to be properly reported, you need to have jest version >= 26.5.0 (see migration notes for alpha.3 release). Otherwise, can you post the relevant debug message from the developer console or OUTPUT channel?

Hey, @connectdotz thanks. I had 25.x.x version of jest. Upgrading it to the 26.6.3 helped. Now it works well.
Thank you for your help.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ngauthier picture ngauthier  ·  37Comments

dandv picture dandv  ·  17Comments

jackfranklin picture jackfranklin  ·  19Comments

luisrudge picture luisrudge  ·  27Comments

erikns picture erikns  ·  16Comments