I am trying to pass in
"HO_1,HO_2"
from a cucumber feature file.
I am trying to pass that value into a Chai include call, so it needs to be in the format of:
"HO_1", "HO_2"
I am currently using a split and join to create the format as such:
const splitE = (('"'+(eventTag.split(",")).join('", "')+'"'));
And this console.log
s:
"HO_1", "HO_2"
But when I then try to pass splitE into the chai call:
expect(estring).to.include(splitE);
Its trying to pass the variable in as a string and it is being passed in as
expect(estring).to.include(""HO_1", "HO_2"");
And it doesn't work, how do I remove the quotes around what I have passed?
怎么都slice
,但引用呢?
expect(estring).to.include(splitE.slice(1, -1));
Actually what you are trying to do is not yet supported in Chai
framework, because .include()
method accepts only one value
, so both your values
will be treated as one string
.
What you can do is to use .satisfy()
method , to check for both substrings
:
expect(estring).to.satisfy(estring =>
eventTag.split(",").some(b => estring.includes(b))
);
You can check, the Check that string contains multiple other strings open issue, in Github for further details.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.