mocha-param icon indicating copy to clipboard operation
mocha-param copied to clipboard

Proposal: describe-included syntax

Open HoldYourWaffle opened this issue 5 years ago • 2 comments

I find myself often writing tests like this:

describe(*name*, function() {
    itParam(*name*, [ data ], function() {
        // ...
    })
    // no other tests
})

I'd propose to add a way to call itParam with a describe call "included", like this:

itParam(*describe name*, *test name*, [ data ], function() { // test name would probably be using ${value}
    // ...
})

HoldYourWaffle avatar Apr 02 '20 15:04 HoldYourWaffle

Although, that syntax might be a mess to parse due to the absence of overloads in JavaScript. Perhaps something like this would be easier:

itParam.describe(*describe name*, *test name*, [ data ], function() { // test name would probably be using ${value}
    // ...
})

HoldYourWaffle avatar Apr 02 '20 15:04 HoldYourWaffle

I agree with your concern. But I think the first param could be a string or a config object.

This allow multiples describe nesting:

itParam({ 
  describe: {
    description: "outer describe description using value",
    it: "test description using value",
    describe: {
      description: "inner describe description using value",
      it: "another test description using value" 
    }
  }
}, [ data ], ( ) => { 
  // ...
})

Or maybe an introduction of describeParam:

describeParam(
  "Describe description for ${value.outerDescribeDescription}",
  [ data ],
  describeParam(
    "Describe description for ${value.innerDescribeDescription}",
    value, // Data object could be used like this or could be injected by the upper describeParam
    itParam("test description ${value.itDescription}", value, ( ) => { 
      // ...
    })
  )
)

viniciusponciano-tw avatar Sep 14 '21 00:09 viniciusponciano-tw