Skip to content

Commit

Permalink
add attribute event listener
Browse files Browse the repository at this point in the history
  • Loading branch information
bredele committed Sep 25, 2016
1 parent efbddc6 commit 37dbc18
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Test dependencies.
*/

var tape = require('tape')
var vomit = require('..')


tape('should call function on event', (test) => {
test.plan(1)
var btn = vomit`<button onclick="${function() {
test.equal(this.outerHTML, '<button onclick="">hello</button>')
}}">hello</button>`
trigger('click', btn)
})


tape('should call muiltiple function on event', (test) => {
test.plan(1)
var hello = function() {
this.innerHTML += 'hello '
}

var world = function() {
this.innerHTML += 'world!'
}
var btn = vomit`<button onclick="${hello}${world}"></button>`
trigger('click', btn)
test.equal(btn.outerHTML, '<button onclick="">hello world!</button>')
})

/**
* Trigger event.
*
* @pram {String} type
* @param {Element} el
* @api private
*/

function trigger(type, el) {
var event = new Event(type);
el.dispatchEvent(event);
}

0 comments on commit 37dbc18

Please sign in to comment.