chai-snabbdom
snabbdom assertions for chai. Tests your virtual dom elements (vnodes). Snabbdom is the virtual dom implementation chosen to build Cycle.js DOM driver. Forked from André Staltz's chai-virtual-dom.
Summary
// Approximate match
// Use .look.like() to do an approximate assertion.
// Must match: tag name, id, className.
// Must match only if provided in expected: children.
expect(myVTree).to.look.like(expected);
// Accurate match
// Use .look.exactly.like() to do a strict assertion.
// Must match: tag name, id, className, and children.
expect(myVTree).to.look.exactly.like(expected);
Example
var chai = require('chai');
var expect = chai.expect;
chai.use(require('chai-snabbdom'));
var h = require('snabbdom').h;
describe('My snabbdom project', function () {
var myVTree = h('div#foo', [
h('h1.header', {}, 'Welcome to our webpage'),
h('ol.list', {}, [
h('li', {}, 'First thing'),
h('li', {}, 'Second thing'),
h('li', {}, 'Third thing')
]),
]);
it('should look roughly like a list', function () {
var expected = h('div#foo', {}, [
h('h1.header'),
h('ol.list')
]);
expect(myVTree).to.look.like(expected);
});
it('should look exactly like a list', function () {
var expected = h('div#foo', {}, [
h('h1.header', {}, 'Welcome to our webpage'),
h('ol.list', {}, [
h('li', {}, 'First thing'),
h('li', {}, 'Second thing'),
h('li', {}, 'Third thing')
]),
]);
expect(myVTree).to.look.exactly.like(expected);
});
});
LICENSE
Copyright (c) 2017 Mathieu Eveillard. Licensed under the MIT license.