virtual-dom-chai

0.0.1 • Public • Published

virtual-dom-chai

A chai plugin for virtual-dom.
Inspired by staltz/chai-virtual-dom

Usage

Basics:

expect(tree).to.have.tag('div');
expect(tree).to.have.text('hello');
expect(tree).to.have.class('foo');
expect(tree).to.have.classes(['foo', 'bar', 'baz']);
expect(tree).to.have.styles({ left: '10px', top: '0px', width: '20px' });
expect(tree).to.have.children(3);
expect(tree).to.have.attribute('src', 'http://first-image.png');

Subtree expectations:

expect(tree).to.have.a.subtree.with.tag('div').inside;
expect(tree).to.have.a.subtree.with.text('hello').inside;
expect(tree).to.have.a.subtree.with.class('foo').inside;
expect(tree).to.have.a.subtree.with.classes(['foo', 'bar', 'baz']).inside
expect(tree).to.have.a.subtree.with.styles({ left: '10px', top: '0px', width: '20px' }).inside;

Important! To use subtree expectations you must end your chai matchers with 'inside'. If you fail to do this, no assertion will be made by chai, and the expectation will always pass (the value of tree will be ignored).

Chaining:

expect(tree).to.have.tag('div').and.text('world');
expect(tree).to.have.class('div').and.text('world').and.styles({ display: 'none' });
expect(tree).to.have.a.subtree.with.tag('div').with.class('foo').inside;
expect(tree).to.have.a.subtree.with.tag('h1').class('bar').styles({ background: 'red' }).and.text('hello').inside;

Locating:

expect(tree).at.root('.some-class').to.have.tag('div');
expect(tree).at.root('.some-class').to.have.a.subtree.with.tag('h1').inside;

Delegating to core chai:

expect(tree).to.have.children.below(3);
expect(tree).to.have.classes.that.include.members(['hide', 'clearfix']);
expect(tree).to.have.text.that.has.length.within(2,4);
expect(tree).to.have.styles.that.have.all.keys('left', 'display', 'background');

Installation

npm install virtual-dom-chai --save-dev
var chai = require('chai');
chai.use(require('virtual-dom-chai'));

License

MIT License.
Copyright © 2016 James Lawson

Package Sidebar

Install

npm i virtual-dom-chai

Weekly Downloads

0

Version

0.0.1

License

MIT

Last publish

Collaborators

  • jameslawson