1.0.2 • Published 8 years ago

snabbdom-chai v1.0.2

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

snabbdom-chai

Flexible chai matchers for snabbdom

A chai plugin for snabbdom.

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('foo').and.text('world').and.style({ 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').style({ color: 'red' }).and.text('world').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 snabbdom-chai --save-dev
var chai = require('chai');
chai.use(require('snabbdom-chai'));

License

MIT License.
Copyright © 2016 James Lawson