chai-url
一個用於處理網址的 Chai 斷言外掛程式
提供許多用於處理網址的斷言輔助函數。
用法
const chai = require('chai');
chai.use(require('chai-url'));
chai.expect('http://example.com/foo/bar').to.have.path('/foo/bar');
chai.expect('http://example.com/foo/bar').to.have.protocol('http');
可用的匹配器
路徑 (path)
路徑名稱 (pathname)
連接埠 (port)
主機名稱 (hostname)
協定 (protocol)
驗證資訊 (auth)
雜湊 (hash)
在每種情況下,屬性都會根據 Node.js 的 url.parse 方法的對應屬性進行測試。
對於可能分別以 #
和 :
作為前綴/後綴的 hash
和 protocol
屬性,這些字元是可選的,無論是否存在都會匹配。
部分匹配
path
、pathname
、hostname
、auth
和 hash
函數還可以透過在測試語句中使用 contains
子句來基於子字串執行部分匹配。
expect('http://example.com/foo/bar').to.contain.path('/foo');
範例
請參閱此模組的測試以獲取更多範例。