cucumber-js
cucumber-js copied to clipboard
Pass empty string to cucumber Example Tables
We use "apickli": "2.3.3" along with "cucumber": "^6.0.5" in order to achieve better compatibility with the Allure for reporting purposes. If a blank value is added to a data table, we are getting for example:
✖ And I set X-APIKEY header to # node_modules/apickli/apickli-gherkin.js:37
TypeError: Cannot read property 'indexOf' of null
Investigating this issue, I saw that there is a fix for cucumber-jvm here, however, it doesn't seem that this is in cucumber-js. I tried with v7 as well with the same result.
We are interested in having a complete blank value as a header value - in our case - so doing the following variations is not giving the result we want:
Case 1:
| endpoint | apikey |
| testEndpoint | '' |
gives back the literal value of ''
Case 2:
| endpoint | apikey |
| testEndpoint | [blank]|
gives back the literal value of [blank]
Case 3:
| endpoint | apikey |
| testEndpoint | |
breaks with the error shown above.
Is it something you consider to add in? Is there any workaround I'm missing here?
Thanks in advance and keep up the great work guys!
Further details:
- OS: macOS Big Sur 11.4
I've looked into this a bit and think the issue is on the apickli side. I'll post some more detail shortly.
@davidjgoss thanks a lot for the prompt reply. I'll be very interested for your further inputs on that to see if there is a workaround on that in order to bypass this issue. Also, I tried v3.0.1 of apickli with the same results.
Here is there source code of apickli as well:
- https://github.com/apickli/apickli/blob/2a338473958c2c29f8fb55d7f2ed5ae58f35fb0a/source/apickli/apickli.js#L92
- https://github.com/apickli/apickli/blob/2a338473958c2c29f8fb55d7f2ed5ae58f35fb0a/source/apickli/apickli.js#L426
@davidjgoss any news on this please?
Sorry for the late reply @sgkiokas. I was mistaken and you're right, the datatable handling is what gives you the null (interestingly in slightly newer versions a blank cell yields undefined and not null, but for these purposes it's the same outcome).
The pattern from cucumber-jvm for [blank] is interesting, although because it's set at the step definition level, I don't think it would solve your problem on its own since the step definitions are part of the apickli library. I'll keep this ticket open as a feature request.
In the meantime, it might be good for apickli code to handle the case of a nullish value. Although I'm curious about the real world case you're testing with this example - is it the header being set to an empty string, or the header being omitted?
Might be worth separating out Example Tables and Data Tables. While they're the same textual structure, they are different things. Example Tables have their value in lined into the scenario's steps, while Data Tables are provided to the step definition as an argument.
I can't tell from this discussion which case we're talking about.
@davidjgoss thanks for your reply. I'll do a research against apickli and if I cannot find anything, I might raise the relevant issue. Regarding the use case I'm working on as you mentioned, it's around testing the interaction between an API via an API Proxy set in Apigee where the header needs to be an empty value.
@mpkorstanje the above refers to Example Tables. I haven't tried that to Data Tables to be honest yet...
Then we can ignore any thoughts about workarounds for tables.
@davidjgoss I would expect that a pattern matching the empty string provides that to the step definition function as an empty string not as undefined.
Only optional capture groups should able to be null/undefined.
Thanks a lot @davidjgoss and @mpkorstanje. It would be amazing to have this enhancement introduced when time permits :)
Thanks for calling out datatable vs examples @mpkorstanje! I'll look at this again shortly
FYI @davidjgoss, the above was indeed missing from apickli and, after raising it there, the relevant PR was submitted.
That's not really what you want though.
What we want/expect:
setHeader("header-name", "value") --> header-name: value
setHeader("header-name", "") --> header-name:
setHeader("header-name", undefined/null) -->
What you get:
setHeader("header-name", "value") --> header-name: value
setHeader("header-name", "") -->
setHeader("header-name", undefined/null) -->
Hmm not really, unless I'm confusing your example. If I supply "" I get back "" since it's an empty string. If I supply nothing (undefined or null) then the above exception is occurred.