[英]How to determine whether a string contains other strings?
我瀏覽了 Chai 文檔,但找不到解決我的問題的方法。
是否可以使用 Chai 來確定一個字符串是否包含其他字符串?
我知道我可以像下面這樣使用它:
expect('foobar').to.have.string('bar');
但是我如何通過像這樣向它提供一個字符串數組來使用它:
expect('foobar').to.have.string(['foo', 'bar'])
或者只是簡單地:
expect('foobar').to.contain.any([foo', 'bar'])
在這種情況下,您可以使用keys
斷言:
expect('foobar').to.include.keys('foo', 'bar');
您可以使用match
進行正則表達式 OR 檢查。
// PASS for response = "The service is down."
expect(response).to.match(/(down|up)/);
response.should.match(/(down|up)/);
// PASS for response = "The service is up now."
expect(response).to.match(/(down|up)/);
response.should.match(/(down|up)/);
// FAIL for response = ""The service is left or right""
expect(response).to.match(/(down|up)/);
response.should.match(/(down|up)/);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.