Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.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 TypeError:expect(…).to.StartWith不是函数-chai和chakram_Javascript_Api_Automation_Chai_Chakram - Fatal编程技术网

Javascript TypeError:expect(…).to.StartWith不是函数-chai和chakram

Javascript TypeError:expect(…).to.StartWith不是函数-chai和chakram,javascript,api,automation,chai,chakram,Javascript,Api,Automation,Chai,Chakram,我开始编写一些自动化测试(API) 现在我尝试对该端点执行以下操作: 所以我在函数中添加了 expect(response.body.message).to.startsWith('https://images.dog.ceo/breeds/'); 在测试开始时: var chakram = require('chakram'); var chai = require('chai'); chai.use(require('chai-string')) expect = ch

我开始编写一些自动化测试(API)

现在我尝试对该端点执行以下操作:

所以我在函数中添加了

expect(response.body.message).to.startsWith('https://images.dog.ceo/breeds/');   
在测试开始时:

    var chakram = require('chakram');
var chai = require('chai');  
chai.use(require('chai-string'))
expect = chai.expect;    // Using Expect style
expect = chakram.expect;
早些时候,我没有遇到任何问题,但在运行测试后,使用此“expect Start…”我得到: TypeError:expect(…).to.StartWith不是函数-chai和chakram

有人能帮我吗


谢谢

您不需要柴串,只需执行以下操作即可:

expect(response.body.message).to.be.a('string').and.satisfy(msg => msg.startsWith('https://images.dog.ceo/breeds/'));
甚至可以在
满足的
中执行正则表达式

或者最好使用
匹配

const { escapeRegExp } = require('lodash');
expect(response.body.message).to.be.a('string').and.match(/^https:\/\/images\.dog\.ceo\/breeds\//i);
expect(response.body.message).to.be.a('string').and.match(new RegExp('^' + escapeRegExp('https://images.dog.ceo/breeds/'), 'i')); // this is preferred way so you don't have to worry about escaping, rely on lodash method to escape

这听起来很明显…但是你安装了软件包吗?(npm-i chai string)

我生活在以下解决方案中,没有任何外部依赖

expect(result.startsWith("string to match")).to.be.true;

你能不能创造一个新的模型,这样我们就可以复制这个?对我来说很有用。为什么你的代码会一个接一个地为
expect
赋值?听起来可能很明显,但你打开电脑了吗?;)