Jest: Using `.skip` or `.only` inside `.each` test cases

Created on 24 Jan 2019  路  6Comments  路  Source: facebook/jest

I would like to skip a few tests inside an each block, or run only one of them. I was looking for some syntax along the following lines :

describe.each`
   year    | month | day
// ${2045} | ${11} | ${22}
// ${2046} | ${8}  | ${11}
   ${2047} | ${1}  | ${1}
// ${2048} | ${2}  | ${29}
`("date is $day / $month / $year", ({ year, month, day }) => {
    // my tests
})

Is there a way to do this somehow ?

All 6 comments

Hey @aymericbouzy currently the only way you can do this is to remove any tests you don't want to run. If you use the array structure over multiple lines it can be easier to just comment them out, this isn't really possible within a template literal.

describe.each([
  // [2045, 11, 22]
  // [2046, 8, 11]
  [2047, 1, 1]
  // [2048, 2, 29]
])('date is %s / %s / %s', (year, month, day) => {
  // my tests
  expect(1).toBe(2);
});

If we had some sort of conditional test skipping, wr could probably do something here. As we don't (and don't plan to), I don't think this is actionable.

Commenting out (or deleting and reintroducing if you use VCS) is the way to go

I think it's a good idea to allow us specifying certain skip conditions. This is different from commenting them out that skipped test will still be reported and such input is very helpful on tracking todos. So, would be great if jest team would like to implement this!

CC: @SimenB

One way to circumvent :

describe.each`
   year    | month | day   | skiped
   ${2045} | ${11} | ${22} | ${false}
   ${2046} | ${8}  | ${11} | ${false}
   ${2047} | ${1}  | ${1}  | ${true}
   ${2048} | ${2}  | ${29} | ${false}
`("date is $day / $month / $year [skiped: $skiped]", ({ year, month, day, skiped }) => {
  if (!skiped) {
    // my tests
  }
})

@aymericbouzy yup it sounds legit, but just feel not so elegant?... Imagine you have many test blocks inside describe.each that should be skipped for some values, you need to add one field for each of them? :joy:

@yxliang01 I know, that's why I'm asking for the proper feature in the first place 馃槈 I was simply suggesting an alternative for people googling this thread until there is an "elegant" solution.

Was this page helpful?
0 / 5 - 0 ratings