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 ライセンス に基づいてライセンスされています。