Skip to content

Commit 0bd90b5

Browse files
Adds testid guidelines to Styleguide (#2221)
* Update STYLEGUIDE.md * Update STYLEGUIDE.md * Update STYLEGUIDE.md
1 parent 189a098 commit 0bd90b5

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

STYLEGUIDE.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,42 @@ Keeps functions pure.
190190

191191
---
192192

193-
### Use “be” verbs for boolean types. (e.g. `should`/`is`/`can`/`does`/`has`)
193+
### Prefix boolean variables with “to be” verbs.
194+
195+
(e.g. `shouldX`, `isY`, `canZ`, `doesX`, `hasY`, `willZ`)
196+
197+
---
198+
199+
### Follow BEM-ish patterns when hard-coding a `data-testid` or `data-lgid`
200+
201+
1. Prefix with “lg”
202+
2. Words are separated by underscore `_`
203+
3. Blocks are separated by dash `-`
204+
4. Name hierarchy should somewhat match the directory structure
205+
206+
Additionally, a hard-coded `data` attribute should _only_ be placed on a root-level, native HTML element. Components should have their own internal id.
207+
208+
#### Prefer
209+
210+
```jsx
211+
// CalendarCell.tsx
212+
<td data-testid="lg-date_picker-calendar_cell" />
213+
```
214+
215+
#### Avoid
216+
217+
```jsx
218+
// Calendar.tsx
219+
<Cell data-testid="lg-date-picker-calendar-cell" />
220+
```
221+
222+
(Note, this is fine to do in a _test/spec_ file. Just don't hard-code this into the component)
223+
224+
#### Why BEM-_ish_?
225+
226+
BEM uses dashes (`-`) to separate words within a block/element, and a double underscore (`__`) to separate blocks/elements/modifiers.
227+
228+
The main issue with strict BEM syntax is that it creates a poor user experience when editing. In most text editors a Double click or `Option`+`ArrowKey` presses treat underscores as one works and dashes as a separator. For example, to replace the `"calendar_cell"` part in the above example, you can double click it and paste. Or to move the cursor from the end of that string to the previous element you can press `Option` + `ArrowLeft`.
194229

195230
---
196231

0 commit comments

Comments
 (0)