This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

chai-snabbdom

1.0.0 • Public • Published

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.

Package Sidebar

Install

npm i chai-snabbdom

Weekly Downloads

0

Version

1.0.0

License

MIT

Last publish

Collaborators

  • mathieueveillard