mirror of
https://github.com/tabler/tabler.git
synced 2026-10-22 07:44:18 +04:00
Fix the flaky CountUp h:mm test (#3336)
This commit is contained in:
1 parent
330eaea165
commit
914faea116
1 file changed
+4
-1
@@ -3,6 +3,8 @@ import { clearFixture, getFixture } from '../helpers/fixture'
|
||||
import CountUp from '../../src/countup'
|
||||
|
||||
const wait = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms))
|
||||
// Waits for the animation to end instead of a fixed time, since animation frames run late on a slow CI runner.
|
||||
const completed = (el: HTMLElement): Promise<void> => new Promise((resolve) => el.addEventListener('complete.bs.countup', () => resolve(), { once: true }))
|
||||
|
||||
describe('CountUp', () => {
|
||||
let fixtureEl: HTMLElement
|
||||
@@ -254,11 +256,12 @@ describe('CountUp', () => {
|
||||
it('should count a time in minutes and print it as h:mm', async () => {
|
||||
fixtureEl.innerHTML = '<h1 data-countup=\'{"format":"time","suffix":" hrs"}\'>3:28</h1>'
|
||||
|
||||
const done = completed(element())
|
||||
const instance = new CountUp(element(), { autoAnimate: false, duration: 0.1 })
|
||||
expect(instance._endVal).toBe(208)
|
||||
expect(element().textContent).toBe('0:00 hrs')
|
||||
|
||||
await wait(300)
|
||||
await done
|
||||
expect(element().textContent).toBe('3:28 hrs')
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user