Skip to content

Commit 4f38286

Browse files
committed
test(tooltip): refactor methods tests
1 parent 6fbf5d0 commit 4f38286

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

src/components/tooltip/tooltip.spec.ts

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -396,33 +396,44 @@ describe('Tooltip', () => {
396396

397397
describe('Methods` Tests', () => {
398398
beforeEach(async () => {
399-
clock = useFakeTimers({ toFake: ['setTimeout'] });
400399
const container = await fixture(createTooltipWithTarget());
401400
tooltip = container.querySelector(IgcTooltipComponent.tagName)!;
402401
anchor = container.querySelector('button')!;
403402
});
404403

405-
afterEach(() => {
406-
clock.restore();
407-
});
408-
409404
it('calls `show` and `hide` methods successfully and returns proper values', async () => {
410405
expect(tooltip.open).to.be.false;
411406

412-
tooltip.show().then((x) => expect(x).to.be.true);
413-
await clock.tickAsync(DEFAULT_SHOW_DELAY);
414-
await showComplete();
407+
// hide tooltip when already hidden
408+
let animation = await tooltip.hide();
409+
expect(animation).to.be.false;
410+
expect(tooltip.open).to.be.false;
411+
expect(tooltip).dom.to.equal(
412+
'<igc-tooltip>It works!</igc-tooltip>',
413+
DIFF_OPTIONS
414+
);
415415

416+
// show tooltip when hidden
417+
animation = await tooltip.show();
418+
expect(animation).to.be.true;
416419
expect(tooltip.open).to.be.true;
417420
expect(tooltip).dom.to.equal(
418421
'<igc-tooltip open>It works!</igc-tooltip>',
419422
DIFF_OPTIONS
420423
);
421424

422-
tooltip.hide().then((x) => expect(x).to.be.true);
423-
await clock.tickAsync(endTick(DEFAULT_HIDE_DELAY));
424-
await hideComplete();
425+
// show tooltip when already shown
426+
animation = await tooltip.show();
427+
expect(animation).to.be.false;
428+
expect(tooltip.open).to.be.true;
429+
expect(tooltip).dom.to.equal(
430+
'<igc-tooltip open>It works!</igc-tooltip>',
431+
DIFF_OPTIONS
432+
);
425433

434+
// hide tooltip when shown
435+
animation = await tooltip.hide();
436+
expect(animation).to.be.true;
426437
expect(tooltip.open).to.be.false;
427438
expect(tooltip).dom.to.equal(
428439
'<igc-tooltip>It works!</igc-tooltip>',
@@ -433,20 +444,16 @@ describe('Tooltip', () => {
433444
it('calls `toggle` method successfully and returns proper values', async () => {
434445
expect(tooltip.open).to.be.false;
435446

436-
tooltip.toggle().then((x) => expect(x).to.be.true);
437-
await clock.tickAsync(DEFAULT_SHOW_DELAY);
438-
await showComplete();
439-
447+
let animation = await tooltip.toggle();
448+
expect(animation).to.be.true;
440449
expect(tooltip.open).to.be.true;
441450
expect(tooltip).dom.to.equal(
442451
'<igc-tooltip open>It works!</igc-tooltip>',
443452
DIFF_OPTIONS
444453
);
445454

446-
tooltip.toggle().then((x) => expect(x).to.be.true);
447-
await clock.tickAsync(endTick(DEFAULT_HIDE_DELAY));
448-
await hideComplete();
449-
455+
animation = await tooltip.toggle();
456+
expect(animation).to.be.true;
450457
expect(tooltip.open).to.be.false;
451458
expect(tooltip).dom.to.equal(
452459
'<igc-tooltip>It works!</igc-tooltip>',
@@ -703,11 +710,8 @@ describe('Tooltip', () => {
703710
IgcTooltipComponent.tagName
704711
);
705712

706-
first.show().then((x) => expect(x).to.be.true);
707-
last.show().then((x) => expect(x).to.be.true);
708-
await clock.tickAsync(DEFAULT_SHOW_DELAY);
709-
await showComplete(first);
710-
await showComplete(last);
713+
first.show();
714+
last.show();
711715

712716
expect(first.open).to.be.true;
713717
expect(last.open).to.be.true;

0 commit comments

Comments
 (0)