[英]How to remove the double quotes?
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: 我正在尝试将该值传递给Chai包含调用,因此它的格式应为:
"HO_1", "HO_2"
I am currently using a split and join to create the format as such: 我目前正在使用split和join来创建这样的格式:
const splitE = (('"'+(eventTag.split(",")).join('", "')+'"'));
And this console.log
s: 而这个console.log
:
"HO_1", "HO_2"
But when I then try to pass splitE into the chai call: 但是当我然后尝试将splitE传递给chai调用时:
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
. 实际上, Chai
框架尚未支持您要执行的操作,因为.include()
方法仅接受一个value
,因此两个values
都将被视为一个string
。
What you can do is to use .satisfy()
method , to check for both substrings
: 您可以使用.satisfy()
方法来检查两个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. 您可以在Github中检查“ 检查该字符串是否包含其他多个字符串打开问题”,以获取更多详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.