Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用或/和Chai测试包_Javascript_Node.js_Chai - Fatal编程技术网

Javascript 使用或/和Chai测试包

Javascript 使用或/和Chai测试包,javascript,node.js,chai,Javascript,Node.js,Chai,我有下面的代码,我想检查它是否包含这些字段之一(姓名、电子邮件等),我的问题是如何修复此测试代码,或者是否有更好的方法使用相同的功能 //It is work res.body.should.have.property('message') .to.be.a('string') .that.contains('email').and.that.does.not.contain('name'); //it is not

我有下面的代码,我想检查它是否包含这些字段之一(姓名、电子邮件等),我的问题是如何修复此测试代码,或者是否有更好的方法使用相同的功能

//It is work
res.body.should.have.property('message')
                    .to.be.a('string')
                    .that.contains('email').and.that.does.not.contain('name');
//it is not working
res.body.should.have.property('message')
                    .to.be.a('string')
                    .that.contains('name')
                    .or.that.contains('email')
                    .or.that.contains('password');

这回答了你的问题吗?谢谢你,是和否,我发现这个解决方案
。满足((str)=>(/name | email | password/.test(str))?正确:错误)
取决于你发送的链接,但我正在寻找更好更清晰的答案第二个答案如何<代码>expect(1).to.not.be.one([2,3,4])是的,这是一个很好的答案,但我不是在寻找一个精确的匹配,在我的情况下,我有一个字符串,我会检查字符串是否包含这些单词中的一个,因为这个原因它对我不起作用,但再次非常感谢您的帮助@TasosBu