Skip to content

Commit

Permalink
Add event tests
Browse files Browse the repository at this point in the history
  • Loading branch information
him2 committed Nov 1, 2017
1 parent 5fd859e commit 0a8e3fa
Show file tree
Hide file tree
Showing 3 changed files with 1,790 additions and 67 deletions.
67 changes: 0 additions & 67 deletions test/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,73 +89,6 @@ 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)
var a = html`<button onclick=${fail}>OLD</button>`
var b = html`<button>NEW</button>`
var res = morph(a, b)

res.click()

a = html`<button>OLD</button>`
b = html`<button onclick=${pass}>NEW</button>`
res = morph(a, b)

res.click()

function fail (e) {
e.preventDefault()
t.fail('should not be called')
}

function pass (e) {
e.preventDefault()
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) {
t.test('if new tree has no value and old tree does, remove value', function (t) {
t.plan(4)
Expand Down
Loading

0 comments on commit 0a8e3fa

Please sign in to comment.