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 授權條款授權。