Skip to content

Commit

Permalink
Added test for onChange event (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
him2him2 authored and yoshuawuyts committed Oct 30, 2017
1 parent 4c999ca commit 5fd859e
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions test/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ function abstractMorph (morph) {
})
})

function raiseEvent (element, eventName) {
var event = document.createEvent('Event')
event.initEvent(eventName, true, true)
element.dispatchEvent(event)
}

t.test('events', function (t) {
t.test('should copy onclick events', function (t) {
t.plan(1)
Expand All @@ -114,6 +120,40 @@ function abstractMorph (morph) {
t.ok('called')
}
})

t.test('should not copy onchange events', function (t) {
t.plan(1)
var expectationMet = true
var a = html`<select onchange=${fail}><option>1</option><option>2</option></select>`
var b = html`<select><option>1</option><option>2</option></select>`
var res = morph(a, b)

raiseEvent(res, 'change')

function fail (e) {
e.preventDefault()
expectationMet = false
}

t.equal(expectationMet, true, 'result was expected')
})

t.test('should copy onchange events', function (t) {
t.plan(1)
var expectationMet = false
var a = html`<select><option>1</option><option>2</option></select>`
var b = html`<select onchange=${pass}><option>1</option><option>2</option></select>`
var res = morph(a, b)

raiseEvent(res, 'change')

function pass (e) {
e.preventDefault()
expectationMet = true
}

t.equal(expectationMet, true, 'result was expected')
})
})

t.test('values', function (t) {
Expand Down

0 comments on commit 5fd859e

Please sign in to comment.