https://github.com/staltz/chai-virtual-dom
Chai assertion helpers for virtual-dom elements
https://github.com/staltz/chai-virtual-dom
Last synced: 8 months ago
JSON representation
Chai assertion helpers for virtual-dom elements
- Host: GitHub
- URL: https://github.com/staltz/chai-virtual-dom
- Owner: staltz
- License: mit
- Created: 2015-09-10T18:46:51.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2015-09-12T11:24:05.000Z (about 10 years ago)
- Last Synced: 2025-03-28T16:43:38.084Z (8 months ago)
- Language: JavaScript
- Homepage:
- Size: 152 KB
- Stars: 24
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-cyclejs - staltz/chai-virtual-dom ★24 - Chai assertion helpers to test virtual-dom VTrees (Libraries / Utilities)
README
# chai-virtual-dom
[virtual-dom](https://github.com/Matt-Esch/virtual-dom) assertions for chai. Tests your virtual-dom elements (VirtualNodes, or "VTrees").
[](https://www.npmjs.org/package/chai-virtual-dom)
[](https://travis-ci.org/staltz/chai-virtual-dom)
#### Summary
```js
// 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);
```
```js
// 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
```js
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
This is a plugin for the [Chai Assertion Library](http://chaijs.com). Install via [npm](http://npmjs.org).
npm install --save-dev chai-virtual-dom
#### Usage
To use this plugin in your tests, import as such:
```js
var chai = require('chai');
chai.use(require('chai-virtual-dom'));
```
#### LICENSE
Copyright (c) 2015 Andre Staltz
Licensed under the MIT license.