Extension to expect to compares two HTML snippets
Extension to expect to compares two HTML snippets. It normalizes HTML so you can compare regardless of case, whitespacing, quotations, and other syntax differences. Compatible with legacy IE.
npm i --save-dev expect expect-html-equal
var expect = require('expect')
require('expect-html-equal')
it('works', function () {
var input = '<div class="name">Hello</div>'
expect(input).toHtmlEqual('<DIV CLASS=name>Hello</DIV>')
})
API:
expect(actual).toHtmlEqual(other)
expect(actual).toNotHtmlEqual(other)
expect(needle).toHtmlInclude(haystack)
expect(needle).toHtmlExclude(haystack)
expect.normalizeHtml
In node/iojs, it expects a global.document
to exist, so you might want to do
this in a jsdom environment. (eg, mocha-jsdom)
In the browser, you can use the rawgit CDN (change {VERSION}
):
<script src='https://cdn.rawgit.com/mjackson/expect/{VERSION}/dist/expect.min.js'></script>
<script src='https://cdn.rawgit.com/rstacruz/expect-html-equal/{VERSION}/index.js'></script>
expect-html-equal © 2015+, Rico Sta. Cruz. Released under the MIT License. Authored and maintained by Rico Sta. Cruz with help from contributors (list).
ricostacruz.com · GitHub @rstacruz · Twitter @rstacruz