chai-xml
Xml assertions for Chai.
Install
In addition to the chai package, you need to install the plugin :
npm install chai-xml --save-dev
Example
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);
});
});
Usage
- XML must be a string
- Add the property
xml
to your chain - The
equal/eq/equals
methods compare XML instead of the strings - The
valid
method check whether the XML is well-formed
Contributing
Any contribution is welcome! Please check the issues. Do some unit tests as far as possible.
Release History
- 0.4.1 dependency update
- 0.3.0 adding
deep
comparison. Thanks to PR #2- 0.3.1 change package.json keywords
- 0.3.2 Add eslint, fix parsing error when invalid, add package-lock.json
- 0.2.0 initial release. Support
xml
property,valid
method and overwrite theequal/eq/equals
methods
License
Copyright (c) 2014-2023 Bertrand Chevrier
Licensed under the MIT license.