Skip to content

kvnneff/deku-component-mount

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

deku-component-mount Build Status

Mount a Deku component to the DOM to facilitate testing.

Code is originally by Dominic Barnes.

Install

npm install deku-component-mount

Example

import assert from 'assert'
import mount from 'deku-component-mount'
import element from 'virtual-element'
import Mock from 'component-mock'

const Component = {
  render: function () {
    return element('div', {id: 'hello-world'}, 'Hello World!')
  }
}

const node = Mock(Component).render()
const mountedNode = mount(node)

assert(document.getElementById('hello-world')) //=> passes

mountedNode.unmount()

assert(document.getElementById('hello-world')) //=> fails

API

mount(node)

Mount a Deku node to the DOM and return an object with a property element containing a reference to the rendered DOM element and a property unmount containing a function to remove the rendered DOM element from the DOM.

mountedNode.unmount()

Remove the rendered element from the DOM

mountedNode.element

A reference to the mounted dom element

License

MIT

About

Mount a Deku component to the DOM

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published