chai-files

Build Status Build status npm

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 许可证