Skip to content

Commit

Permalink
refactor: add util type for asserting on global test props (#3285)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcfranco authored Oct 19, 2021
1 parent f3030ce commit 30288ae
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CSS, DEFAULT_COLOR, DEFAULT_STORAGE_KEY_PREFIX, DIMENSIONS, TEXT } from
import { E2EElement, E2EPage, EventSpy, newE2EPage } from "@stencil/core/testing";
import { ColorValue } from "./interfaces";
import SpyInstance = jest.SpyInstance;
import { selectText } from "../../tests/utils";
import { GlobalTestProps, selectText } from "../../tests/utils";

describe("calcite-color-picker", () => {
let consoleSpy: SpyInstance;
Expand Down Expand Up @@ -474,10 +474,9 @@ describe("calcite-color-picker", () => {
await page.waitForChanges();
x = 0;

type TestWindow = {
type TestWindow = GlobalTestProps<{
internalColor: HTMLCalciteColorPickerElement["color"];
} & Window &
typeof globalThis;
}>;

await page.evaluateHandle(() => {
const color = document.querySelector("calcite-color-picker");
Expand Down
7 changes: 3 additions & 4 deletions src/components/calcite-tree/calcite-tree.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { newE2EPage } from "@stencil/core/testing";
import { accessible, HYDRATED_ATTR, defaults } from "../../tests/commonTests";
import { html } from "../../tests/utils";
import { GlobalTestProps, html } from "../../tests/utils";
import { CSS } from "../calcite-tree-item/resources";
import { TreeSelectionMode } from "./interfaces";

Expand Down Expand Up @@ -244,10 +244,9 @@ describe("calcite-tree", () => {

const [item1, item2] = await page.findAll("calcite-tree-item");

type TestWindow = {
type TestWindow = GlobalTestProps<{
selectedIds: string[];
} & Window &
typeof globalThis;
}>;

await page.evaluateHandle(() =>
document.addEventListener("calciteTreeSelect", ({ detail }: CustomEvent) => {
Expand Down
4 changes: 2 additions & 2 deletions src/tests/commonTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { JSX } from "../components";
import { toHaveNoViolations } from "jest-axe";
import axe from "axe-core";
import { config } from "../../stencil.config";
import { html } from "./utils";
import { GlobalTestProps, html } from "./utils";

expect.extend(toHaveNoViolations);

type CalciteComponentTag = keyof JSX.IntrinsicElements;
type AxeOwningWindow = Window & { axe: typeof axe } & typeof globalThis;
type AxeOwningWindow = GlobalTestProps<{ axe: typeof axe }>;
type ComponentHTML = string;
type TagOrHTML = CalciteComponentTag | ComponentHTML;

Expand Down
5 changes: 5 additions & 0 deletions src/tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { E2EElement, E2EPage } from "@stencil/core/testing";
import { BoundingBox, JSONObject } from "puppeteer";
import dedent from "dedent";

/**
* Util to help type global props for testing.
*/
export type GlobalTestProps<T> = T & Window & typeof globalThis;

type DragAndDropSelector = string | SelectorOptions;

type PointerPosition = {
Expand Down

0 comments on commit 30288ae

Please sign in to comment.