Skip to content

Commit c1b1afe

Browse files
test: properly reset global tooltip state (#6033) (#6038)
Co-authored-by: Sascha Ißbrücker <sissbruecker@vaadin.com>
1 parent b35a2e8 commit c1b1afe

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

packages/tooltip/src/vaadin-tooltip.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ let warmedUp = false;
2626
let warmUpTimeout = null;
2727
let cooldownTimeout = null;
2828

29+
/**
30+
* Resets the global tooltip warmup and cooldown state.
31+
* Only for internal use in tests.
32+
* @private
33+
*/
34+
export function resetGlobalTooltipState() {
35+
warmedUp = false;
36+
clearTimeout(warmUpTimeout);
37+
clearTimeout(cooldownTimeout);
38+
closing.clear();
39+
}
40+
2941
/**
3042
* Controller for handling tooltip opened state.
3143
*/

packages/tooltip/test/tooltip-timers.test.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from '@vaadin/testing-helpers';
1212
import sinon from 'sinon';
1313
import './not-animated-styles.js';
14-
import { Tooltip } from '../vaadin-tooltip.js';
14+
import { resetGlobalTooltipState, Tooltip } from '../vaadin-tooltip.js';
1515
import { mouseenter, mouseleave } from './helpers.js';
1616

1717
describe('timers', () => {
@@ -42,8 +42,7 @@ describe('timers', () => {
4242
});
4343

4444
afterEach(async () => {
45-
// Wait for cooldown timeout.
46-
await aTimeout(0);
45+
resetGlobalTooltipState();
4746
});
4847

4948
it('should open the overlay after a delay on mouseenter', async () => {
@@ -73,8 +72,7 @@ describe('timers', () => {
7372
});
7473

7574
afterEach(async () => {
76-
// Wait for cooldown timeout.
77-
await aTimeout(0);
75+
resetGlobalTooltipState();
7876
});
7977

8078
it('should open the overlay after a delay on keyboard focus', async () => {
@@ -104,8 +102,7 @@ describe('timers', () => {
104102
});
105103

106104
afterEach(async () => {
107-
// Wait for cooldown timeout.
108-
await aTimeout(1);
105+
resetGlobalTooltipState();
109106
});
110107

111108
it('should close the overlay after a hide delay on mouseleave', async () => {
@@ -432,8 +429,7 @@ describe('timers', () => {
432429
});
433430

434431
afterEach(async () => {
435-
// Wait for cooldown timeout.
436-
await aTimeout(2);
432+
resetGlobalTooltipState();
437433
});
438434

439435
it('should close first tooltip and open the second one without waiting for hover delay', async () => {

0 commit comments

Comments
 (0)