Chai Match

用於 Chai.js 的進階正規表示式斷言。

安裝

npm i --save-dev chai-match
var chai = require('chai');
chai.use(require('chai-match'));

API

.capture(n)

將斷言物件設定為先前匹配的捕獲。

expect('some thing to test').to.match(/some (\w+) to test/).and.capture(0).equals('thing');
'Here in London'.should.match(/(here|there) in (\w+)/i).and.capture(1).equals('London');