Skip to content

bahmutov/snap-shot-jsdom-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

  • Run mocha with mocha -r jsdom-global/register spec.js option that loads jsdom-global module
  • Beautify the element's HTML representation, for example
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))
})
  • Alternatively use JSON representation of the DOM tree
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))
})

About

jsdom example for snap-shot https://github.com/bahmutov/snap-shot project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published