chai-json
一个用于验证 JSON 文件的 Chai 插件
使用
服务器端
从 npm 安装
$ npm install chai-json
让 Chai 使用 chai-fs 模块
var chai = require('chai');
chai.use(require('chai-json'));
断言
jsonFile()
断言一个文件是 JSON 文件
expect(testFile).to.be.a.jsonFile();
jsonObj()
断言给定的 jsonFile 等于一个 JavaScript 对象。
expect(testFile).to.be.a.jsonFile().and.to.be.jsonObj(jsonObj);
jsonWithProps()
断言 jsonFile 包含一个具有给定属性的对象
/*
Content of testFile:
[{"repoName":"giper","labName":"TelnetClientSniffing_1","state":"STOPPED"},{"repoName":"giper","labName":"ErrorSameSubnet","state":"STOPPED"},
{"repoName":"giper","labName":"ErrorSamePort","state":"STOPPED"},
{"repoName":"giper","labName":"ErrorWrongAction","state":"STOPPED"},{"repoName":"giper","labName":"ErrorNoDefinedAction","state":"NO_NETWORK"},{"repoName":"giper","labName":"ErrorCopyFile","state":"STOPPED"},
{"repoName":"giper","labName":"TestActionNoArgs","state":"STOPPED"}
]
*/
expect(testFile).to.be.a.jsonFile().and.contain.jsonWithProps({ repoName: 'giper' });
贡献
欢迎贡献。请遵循代码、测试和样式模式,并保持 Eslint 的正常运行。查看 Airbnb 样式指南以获取更多信息。
构建 & 测试
在你的 git 签出中安装开发依赖
$ npm install
运行测试
$ mocha test
许可证
根据 MIT 许可证授权。