4

I'm using cypress-each to run dynamic tests, but the number of tests overall is large and I'd like to use cypress-grep to add @smoke tags to the data, and run a fraction of the tests.

How do I add tags to

const title = (data) => `Testing ${data}`
it.each(data)(title, (data) => {})

I can use a function to customize the title, how can customize the options object?

This what I've tried,

const title = (data) => `Testing ${data}`
it.each(data)(title, {tags: '@smoke'}, (data) => {})

but obviously it doesn't work - the smoke tag is applied to all test (added as example of tag syntax).

Thelonious
  • 146
  • 10

1 Answers1

4

I don't think you can add tags dynamically to cypress-each.

But you could do it the standard way if you wrap the data in objects.

const data = [
  {value:'a', tag:'@smoke},            // only first will run when grepping @smoke
  {value:'b'}, 
  {value:'c'}
]

data.forEach(data => {
  const title = `Testing ${data}`
  const options = {tags: data.tag}    // when data.tag is undefined, 
                                      // effectively no tag applies 

  it(title, options, (data) => {
    ...
  })
})
Fody
  • 23,754
  • 3
  • 20
  • 37