Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywhy committed Oct 21, 2024
1 parent c05ac41 commit 0d0c091
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
2 changes: 2 additions & 0 deletions test/alert_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ describe('AlertController', () => {
await loadFixture('alerts/alert_default.html')
expect(fetchElement().className.includes("hidden")).to.equal(false)

// Timeout so click() doesn't happen before setTimeout runs in controller.
await aTimeout(0)
const closeButton = document.querySelector("[data-action='alert#close']")
closeButton.click()

Expand Down
3 changes: 2 additions & 1 deletion test/dropdown_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { html, fixture, expect, nextFrame } from '@open-wc/testing'
import { fixture, expect, nextFrame, aTimeout } from '@open-wc/testing'
import { fetchFixture } from './test_helpers'

import { Application } from '@hotwired/stimulus'
Expand All @@ -19,6 +19,7 @@ describe('DropdownController', () => {
const button = document.querySelector('[data-action="dropdown#toggle:stop"]')
button.click()
await nextFrame()
await nextFrame()
expect(menu.className.includes('hidden')).to.equal(false)
})
})
Expand Down
21 changes: 12 additions & 9 deletions test/popover_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { html, fixture, expect, nextFrame } from '@open-wc/testing'
import { html, fixture, expect, nextFrame, aTimeout } from '@open-wc/testing'

import { Application } from '@hotwired/stimulus'
import Popover from '../src/popover'
Expand Down Expand Up @@ -36,25 +36,28 @@ describe('PopoverController', () => {
})
target.dispatchEvent(mouseover)
await nextFrame()
await nextFrame()
expect(target.className.includes('hidden')).to.equal(false)
})

it('mouseOut adds hidden class', (done) => {
it('mouseOut adds hidden class', async () => {
const target = document.querySelector('[data-popover-target="content"]')
target.className.replace('hidden', '')
const event = new MouseEvent('mouseleave', {
view: window,
bubbles: true,
cancelable: true,
})

target.dispatchEvent(event)
setTimeout(() => {
expect(target.className.includes('transition-opacity')).to.equal(true)
}, 10)
setTimeout(() => {
expect(target.className.includes('hidden')).to.equal(true)
done()
}, 101)

await nextFrame()
await nextFrame()
expect(target.className.includes('transition-opacity')).to.equal(true)

await nextFrame()
expect(target.className.includes('hidden')).to.equal(true)
expect(target.className.includes('transition-opacity')).to.not.equal(true)
})
})
})
2 changes: 2 additions & 0 deletions test/toggle_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ describe('ToggleController', () => {
await nextFrame()
action.click()
await nextFrame()
await nextFrame()
await nextFrame()

expect(target.className.includes('class1')).to.equal(true)
expect(target.className.includes('class2')).to.equal(true)
Expand Down

0 comments on commit 0d0c091

Please sign in to comment.