chai-xml
Chai 的 XML 断言。
安装
除了 chai 包,您还需要安装插件
npm install chai-xml --save-dev
示例
var chai = require('chai');
var expect = require('chai').expect;
var chaiXml = require('chai-xml');
//loads the plugin
chai.use(chaiXml);
describe('assert some xml', function(){
var someXml = '<root>\n\t<child name="foo" value="bar"></child>\n</root>';
var otherXml = '<root><child value="bar" name="foo" /></root>';
it("should be valid", function(){
expect(someXml).xml.to.be.valid();
});
it("should be the same string as otherXml ", function(){
expect(someXml).to.not.equal(otherXml);
});
it("should be the same XML as otherXml ", function(){
expect(someXml).xml.to.equal(otherXml);
});
it("should be the same XML ignoring the whitespace at the begining and end of the text nodes", function () {
var formattedXml = "<tag>\n\tContent\n</tag>";
var unformattedXml = "<tag>Content</tag>";
expect(formattedXml).xml.to.deep.equal(unformattedXml);
});
});
用法
- XML 必须是 字符串
- 在您的链中添加属性
xml
- 方法
equal/eq/equals
用于比较 XML,而不是字符串 - 方法
valid
用于检查 XML 是否格式良好
贡献
任何贡献都受欢迎!请查看 问题。尽可能进行一些单元测试。
发布历史
- 0.4.1 依赖更新
- 0.3.0 添加
deep
比较。感谢 PR #2- 0.3.1 修改 package.json 关键字
- 0.3.2 添加 eslint,修复无效时解析错误,添加 package-lock.json
- 0.2.0 初始发布。支持
xml
属性,valid
方法,并覆盖equal/eq/equals
方法
许可证
版权所有 (c) 2014-2023 Bertrand Chevrier
根据 MIT 许可证授权。