staltz/chai-virtual-dom
Chai assertion helpers for virtual-dom elements
{ "createdAt": "2015-09-10T18:46:51Z", "defaultBranch": "master", "description": "Chai assertion helpers for virtual-dom elements", "fullName": "staltz/chai-virtual-dom", "homepage": "", "language": "JavaScript", "name": "chai-virtual-dom", "pushedAt": "2015-09-12T11:24:05Z", "stargazersCount": 24, "topics": [], "updatedAt": "2019-08-18T16:51:27Z", "url": "https://github.com/staltz/chai-virtual-dom"}chai-virtual-dom
Section titled “chai-virtual-dom”virtual-dom assertions for chai. Tests your virtual-dom elements (VirtualNodes, or “VTrees”).
Summary
Section titled “Summary”// Approximate match//// Use .look.like() to do an approximate assertion.// Must match: tagName, 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: tagName, id, className, and children.expect(myVTree).to.look.exactly.like(expected);Example
Section titled “Example”var chai = require('chai');var expect = chai.expect;chai.use(require('chai-virtual-dom'));var h = require('virtual-dom').h;
describe('My virtual-dom 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); });});Installation
Section titled “Installation”This is a plugin for the Chai Assertion Library. Install via npm.
npm install --save-dev chai-virtual-domTo use this plugin in your tests, import as such:
var chai = require('chai');chai.use(require('chai-virtual-dom'));LICENSE
Section titled “LICENSE”Copyright (c) 2015 Andre Staltz Licensed under the MIT license.