diff --git a/core/js/tests/unit/countup.spec.ts b/core/js/tests/unit/countup.spec.ts index f5fea6271..da4dfe8ec 100644 --- a/core/js/tests/unit/countup.spec.ts +++ b/core/js/tests/unit/countup.spec.ts @@ -3,6 +3,8 @@ import { clearFixture, getFixture } from '../helpers/fixture' import CountUp from '../../src/countup' const wait = (ms: number): Promise => 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 => 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 = '

3:28

' + 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') })