Javascript TypeError:expect(…).to.StartWith不是函数-chai和chakram
我开始编写一些自动化测试(API) 现在我尝试对该端点执行以下操作: 所以我在函数中添加了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
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
赋值?听起来可能很明显,但你打开电脑了吗?;)