From 4d62af42f5cfa92b21af8a04be4ec5cd1a743b5c Mon Sep 17 00:00:00 2001 From: Jacob Pihl Date: Tue, 7 Jan 2025 15:29:47 +0100 Subject: [PATCH] Added type safety to custom data-cy command As data-cy attributes are the preferred way to select element within Cypress, I've enhanced the custom `cy.dataCy()` command to use constants instead of a string. This ensures that custom data selectors cannot have typos or accidential changes. To make this work, I had to consolidate cypress.d.ts and commands.ts as a d.ts file cannot import other files dynamically. --- components/global/header/Header.tsx | 3 ++- cypress/cypress.d.ts | 8 -------- cypress/e2e/frontpage.cy.ts | 1 + cypress/support/commands.ts | 13 ++++++++++++- cypress/support/constants.ts | 5 +++++ 5 files changed, 20 insertions(+), 10 deletions(-) delete mode 100644 cypress/cypress.d.ts create mode 100644 cypress/support/constants.ts diff --git a/components/global/header/Header.tsx b/components/global/header/Header.tsx index faf55ee..94b0850 100644 --- a/components/global/header/Header.tsx +++ b/components/global/header/Header.tsx @@ -5,6 +5,7 @@ import DarkModeToggle from "@/components/shared/darkModeToggle/DarkModeToggle" import Icon from "@/components/shared/icon/Icon" import SearchInput from "@/components/shared/searchInput/SearchInput" import SmartLink from "@/components/shared/smartLink/SmartLink" +import { cyKeys } from "@/cypress/support/constants" import ProfileButton from "./ProfileButton" @@ -15,7 +16,7 @@ function Header() {

Biblioterernes ebøger og lydbøger

-
+