Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including chai-xml with all npm packages installed. Try it out:

var chaiXml = require("chai-xml")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

chai-xml v0.3.2

Xml assertions for Chai


Xml assertions for Chai.


In addition to the chai package, you need to install the plugin :

npm install chai-xml --save-dev


var chai    = require('chai');
var expect  = require('chai').expect;
var chaiXml = require('chai-xml');

//loads the plugin

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(){

    it("should be the same string as otherXml ", function(){
    it("should be the same XML as otherXml ", function(){

    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>";


  • 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


Any contribution is welcome! Please check the issues. Do some unit tests as far as possible.

Release History

  • 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


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

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free