chai-xml
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/chai-xml package

0.4.1 • Public • Published

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 the equal/eq/equals methods

License

Copyright (c) 2014-2023 Bertrand Chevrier
Licensed under the MIT license.

Package Sidebar

Install

npm i chai-xml

Weekly Downloads

11,830

Version

0.4.1

License

none

Unpacked Size

13.2 kB

Total Files

9

Last publish

Collaborators

  • krampstudio