You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/pages/teamshares/recipes/cypress.md
+29-50
Original file line number
Diff line number
Diff line change
@@ -5,45 +5,18 @@ meta:
5
5
6
6
# Shoelace & Cypress
7
7
8
-
> Tips for testing Shoelace components with Cypress
8
+
> Testing Shoelace components with Cypress
9
9
10
-
## TL;DR
10
+
## Cypress Commands Cheat Sheet
11
11
12
-
For the most part, you can use Shoelace components the same way you'd use their HTML equivalents, since they emit many of the same events (`click`, `focus`, etc). But like all web components, Shoelace components encapsulate their internal parts within the [shadow dom](https://css-tricks.com/styling-in-the-shadow-dom-with-css-shadow-parts/).
13
-
14
-
This means that the internals of Shoelace components aren't available directly on the DOM (via `document.querySelector`, etc.), but have to be queried via the [`Element.shadowRoot` property](https://developer.mozilla.org/en-US/docs/Web/API/Element/shadowRoot).
15
-
16
-
Cypress provides a convenience method for accessing the shadow DOM via the [`.shadow()` method.](https://docs.cypress.io/api/commands/shadow).
17
-
18
-
For example, to find the anchor tag within a link button:
@@ -63,7 +36,7 @@ Also see below for more on testing Shoelace design system components with Cypres
63
36
64
37
## Generic Commands
65
38
66
-
The following are generic Cypress commands that can be used for testing Shoelace design system components:
39
+
Generic Cypress commands that can be used for testing Shoelace design system components:
67
40
68
41
### `click()`
69
42
@@ -73,10 +46,6 @@ Use to **click** an element like [sl-button](/components/button) or radio item i
73
46
cy.get(`[data-test-id="item-test-1"]`).click();
74
47
```
75
48
76
-
:::tip
77
-
What other elements does this work for?
78
-
:::
79
-
80
49
### `should('have.prop')`
81
50
82
51
Use on boolean elements like [sl-checkbox](/components/checkbox/#with-cypress) and [sl-switch](/components/switch/#with-cypress) to verify whether the input is checked:
@@ -106,13 +75,9 @@ Can also use to verify that an input does **NOT** have a certain value:
The following are custom Cypress commands created for testing Shoelace design system components:
80
+
Custom Cypress commands created for testing Shoelace design system components:
116
81
117
82
### `cy.slCheckboxCheck()`
118
83
@@ -162,10 +127,6 @@ Use to **focus** on elements like [sl-input](/components/input/#with-cypress) an
162
127
cy.slFocus(`[data-test-id="input-test"]`);
163
128
```
164
129
165
-
:::tip
166
-
What other elements does this work for?
167
-
:::
168
-
169
130
### `cy.slClear()`
170
131
171
132
Use to **clear**[sl-input](/components/input/#with-cypress):
@@ -174,10 +135,6 @@ Use to **clear** [sl-input](/components/input/#with-cypress):
174
135
cy.slClear(`[data-test-id="input-test"]`);
175
136
```
176
137
177
-
:::tip
178
-
What other elements does this work for?
179
-
:::
180
-
181
138
### `cy.slTextAreaClear()`
182
139
183
140
Use to **clear**[sl-textarea](/components/textarea/#with-cypress):
@@ -220,6 +177,28 @@ You can find additional documentation for testing specific components with Cypre
220
177
-[sl-switch](/components/switch/#testing)
221
178
-[sl-textarea](/components/textarea/#testing)
222
179
180
+
## Writing Custom Cypress Commands
181
+
182
+
For the most part, you can use Shoelace components the same way you'd use their HTML equivalents, since they emit many of the same events (`click`, `focus`, etc).
183
+
184
+
But like all web components, Shoelace components encapsulate their internal parts within the [shadow dom](https://css-tricks.com/styling-in-the-shadow-dom-with-css-shadow-parts/).
185
+
186
+
This means that the internals of Shoelace components aren't available directly on the DOM (via `document.querySelector`, etc.), but have to be queried via the [`Element.shadowRoot` property](https://developer.mozilla.org/en-US/docs/Web/API/Element/shadowRoot).
187
+
188
+
Cypress provides a convenience method for accessing the shadow DOM via the [`.shadow()` method.](https://docs.cypress.io/api/commands/shadow).
189
+
190
+
For example, to find the anchor tag within a link button:
0 commit comments