chai-files
用於 chai 的檔案系統斷言
安裝
npm install --save-dev chai-files
使用方式
在匯入 chai
後,加入以下程式碼以使用 chai-files
斷言
var chai = require('chai');
var chaiFiles = require('chai-files');
chai.use(chaiFiles);
var expect = chai.expect;
var file = chaiFiles.file;
var dir = chaiFiles.dir;
.to.exist
檢查檔案或目錄是否存在
expect(file('index.js')).to.exist;
expect(file('index.coffee')).to.not.exist;
expect(dir('foo')).to.exist;
expect(dir('missing')).to.not.exist;
.to.equal(…)
檢查檔案內容是否等於一個字串
expect(file('foo.txt')).to.equal('foo');
expect(file('foo.txt')).to.not.equal('bar');
expect('foo').to.equal(file('foo.txt'));
expect('foo').to.not.equal(file('foo.txt'));
.to.equal(file(…))
檢查檔案是否等於另一個檔案
expect(file('foo.txt')).to.equal(file('foo-copy.txt'));
expect(file('foo.txt')).to.not.equal(file('bar.txt'));
.to.be.empty
檢查檔案或目錄是否為空
expect(file('empty.txt')).to.be.empty;
expect(file('foo.txt')).to.not.be.empty;
expect(dir('empty')).to.be.empty;
expect(dir('foo')).to.not.be.empty;
.to.contain(…)
檢查檔案是否包含一個字串
expect(file('foo.txt')).to.contain('foo');
expect(file('foo.txt')).to.not.contain('bar');
.to.match(/…/)
檢查檔案是否符合正規表示式
expect(file('foo.txt')).to.match(/fo+/);
expect(file('foo.txt')).to.not.match(/bar?/);
授權條款
chai-files 採用 MIT 授權條款。