Skip to content

Commit

Permalink
chore: updated tooltip test
Browse files Browse the repository at this point in the history
  • Loading branch information
agliga committed Oct 31, 2024
1 parent 93ac6a2 commit 05e4cdb
Showing 1 changed file with 6 additions and 28 deletions.
34 changes: 6 additions & 28 deletions src/components/ebay-tooltip/test/test.browser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterEach, beforeEach, describe, it, expect, vi } from "vitest";
import { afterEach, beforeEach, describe, it, expect } from "vitest";
import { composeStories } from "@storybook/marko";
import { render, fireEvent, cleanup, waitFor } from "@marko/testing-library";
import * as stories from "../tooltip.stories";
Expand All @@ -12,16 +12,11 @@ let component;

const renderBodyText = "View options";

describe("given the default tooltip", () => {
describe("default tooltip", () => {
beforeEach(async () => {
vi.useFakeTimers();
component = await render(Standard);
});

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

describe("when the host element is hovered", () => {
beforeEach(async () => {
await fireEvent.mouseEnter(component.getByText(renderBodyText));
Expand All @@ -33,29 +28,12 @@ describe("given the default tooltip", () => {
);
});

describe("when the host element loses hover", () => {
it("then it emits the collapse event", async () => {
await fireEvent.mouseLeave(
component.getByText(renderBodyText).parentElement,
);

await vi.advanceTimersByTimeAsync(500);
await waitFor(
() => expect(component.emitted("collapse")).has.length(1),
2000,
);
});
});

describe("when the escape key is pressed", () => {
it("then it emits the collapse event", async () => {
await fireEvent.keyDown(
component.getByText(renderBodyText).parentElement,
{
key: "Escape",
keyCode: 27,
},
);
await fireEvent.keyDown(document, {
key: "Escape",
keyCode: 27,
});

await waitFor(() =>
expect(component.emitted("collapse")).has.length(1),
Expand Down

0 comments on commit 05e4cdb

Please sign in to comment.