Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions projects/coreui-angular/src/lib/popover/popover.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ describe('PopoverDirective', () => {
});

afterEach(() => {
vi.useRealTimers();
vi.restoreAllMocks();
vi.useRealTimers();
});

it('should create an instance', () => {
Expand Down Expand Up @@ -155,22 +155,29 @@ describe('PopoverDirective', () => {
it('should not run the show timer when destroyed before the popover shows', async () => {
visible.set(true);
fixture.detectChanges();
const popover = document.getElementById(
fixture.nativeElement.getAttribute('aria-describedby') ?? ''
) as HTMLElement;
await vi.advanceTimersByTimeAsync(50);
fixture.destroy();
await vi.advanceTimersByTimeAsync(0);
expect(vi.getTimerCount()).toBe(0);
await vi.advanceTimersByTimeAsync(150);
expect(popover.classList.contains('d-none')).toBe(true);
});

it('should leave no pending timers when destroyed while the popover hides', async () => {
it('should cancel the hide timer when destroyed while the popover hides', async () => {
visible.set(true);
fixture.detectChanges();
await vi.runAllTimersAsync();
const setTimeoutSpy = vi.spyOn(globalThis, 'setTimeout');
const clearTimeoutSpy = vi.spyOn(globalThis, 'clearTimeout');
visible.set(false);
fixture.detectChanges();
await vi.advanceTimersByTimeAsync(50);
const hideTimer =
setTimeoutSpy.mock.results[setTimeoutSpy.mock.calls.findIndex(([, delay]) => delay === 300)]?.value;
expect(hideTimer).toBeDefined();
fixture.destroy();
await vi.advanceTimersByTimeAsync(0);
expect(vi.getTimerCount()).toBe(0);
expect(clearTimeoutSpy).toHaveBeenCalledWith(hideTimer);
});

it('should destroy Popper when the popover hides', async () => {
Expand Down
19 changes: 13 additions & 6 deletions projects/coreui-angular/src/lib/tooltip/tooltip.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ describe('TooltipDirective', () => {
});

afterEach(() => {
vi.useRealTimers();
vi.restoreAllMocks();
vi.useRealTimers();
});

it('should create an instance', () => {
Expand Down Expand Up @@ -156,22 +156,29 @@ describe('TooltipDirective', () => {
it('should not run the show timer when destroyed before the tooltip shows', async () => {
visible.set(true);
fixture.detectChanges();
const tooltip = document.getElementById(
fixture.nativeElement.getAttribute('aria-describedby') ?? ''
) as HTMLElement;
await vi.advanceTimersByTimeAsync(50);
fixture.destroy();
await vi.advanceTimersByTimeAsync(0);
expect(vi.getTimerCount()).toBe(0);
await vi.advanceTimersByTimeAsync(150);
expect(tooltip.classList.contains('d-none')).toBe(true);
});

it('should leave no pending timers when destroyed while the tooltip hides', async () => {
it('should cancel the hide timer when destroyed while the tooltip hides', async () => {
visible.set(true);
fixture.detectChanges();
await vi.runAllTimersAsync();
const setTimeoutSpy = vi.spyOn(globalThis, 'setTimeout');
const clearTimeoutSpy = vi.spyOn(globalThis, 'clearTimeout');
visible.set(false);
fixture.detectChanges();
await vi.advanceTimersByTimeAsync(50);
const hideTimer =
setTimeoutSpy.mock.results[setTimeoutSpy.mock.calls.findIndex(([, delay]) => delay === 300)]?.value;
expect(hideTimer).toBeDefined();
fixture.destroy();
await vi.advanceTimersByTimeAsync(0);
expect(vi.getTimerCount()).toBe(0);
expect(clearTimeoutSpy).toHaveBeenCalledWith(hideTimer);
});

it('should destroy Popper when the tooltip hides', async () => {
Expand Down
Loading