Skip to content

Commit

Permalink
test: update spec for sibling adjacent mouseenter/mouseleave events
Browse files Browse the repository at this point in the history
there is a regression introduced by twbs#33310 - this would have catched that
  • Loading branch information
alpadev committed Apr 18, 2021
1 parent 69f5c01 commit 88ae2ac
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion js/tests/unit/dom/event-handler.spec.js
Expand Up @@ -86,13 +86,15 @@ describe('EventHandler', () => {
'<div class="deep"></div>',
'</div>',
'</div>',
'<div class="sibling"></div>',
'</div>'
]

const outer = fixtureEl.querySelector('.outer')
const inner = fixtureEl.querySelector('.inner')
const nested = fixtureEl.querySelector('.nested')
const deep = fixtureEl.querySelector('.deep')
const sibling = fixtureEl.querySelector('.sibling')

const enterSpy = jasmine.createSpy('mouseenter')
const leaveSpy = jasmine.createSpy('mouseleave')
Expand All @@ -104,6 +106,14 @@ describe('EventHandler', () => {
EventHandler.on(outer, 'mouseenter', '.inner', delegateEnterSpy)
EventHandler.on(outer, 'mouseleave', '.inner', delegateLeaveSpy)

EventHandler.on(sibling, 'mouseenter', () => {
expect(enterSpy.calls.count()).toBe(2)
expect(leaveSpy.calls.count()).toBe(2)
expect(delegateEnterSpy.calls.count()).toBe(2)
expect(delegateLeaveSpy.calls.count()).toBe(2)
done()
})

const moveMouse = (from, to) => {
from.dispatchEvent(new MouseEvent('mouseout', {
bubbles: true,
Expand All @@ -116,6 +126,7 @@ describe('EventHandler', () => {
}))
}

// from outer to deep and back to outer (nested)
moveMouse(outer, inner)
moveMouse(inner, nested)
moveMouse(nested, deep)
Expand All @@ -128,7 +139,10 @@ describe('EventHandler', () => {
expect(leaveSpy.calls.count()).toBe(1)
expect(delegateEnterSpy.calls.count()).toBe(1)
expect(delegateLeaveSpy.calls.count()).toBe(1)
done()

// from outer to inner to sibling (adjacent)
moveMouse(outer, inner)
moveMouse(inner, sibling)
}, 20)
})
})
Expand Down

0 comments on commit 88ae2ac

Please sign in to comment.