Home

Awesome

snap-shot-jsdom-test

jsdom example for snap-shot project

Build status

This is a test project for snap-shot for snapshot testing.

See spec.js for actual test code. In principle to use snapshot testing on Node with jsdom and mocha

const clean = require('clean-html').clean
const snapshot = require('snap-shot')

const pretty = html => {
  let result
  clean(html, out => {
    result = out
  })
  return result
}
it('can serialize div using js-beautify.html', function () {
  const div = document.createElement('div')
  div.innerHTML = '<div class="hello"><div id="message">Hello World</div></div>'
  snapshot(pretty(div.innerHTML))
})
const elementToJson = require('@wildpeaks/snapshot-dom').toJSON
const snapshot = require('snap-shot')
it('can serialize div', function () {
  const div = document.createElement('div')
  div.innerHTML = '<p class="hello">Hello World</p>'
  snapshot(elementToJson(div))
})