Skip to content

Dev #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
{
"cSpell.words": [
"beus",
"brc",
"brcc",
"brh",
"brhl",
"bro",
"bron",
"bteew",
"btesw",
"btew",
"btf",
"bti",
"bts",
"btsi",
"btsw",
"deinsoftware",
"Equiman",
"gabr",
"gabro",
"gbrc",
"gbrcc",
"gbrh",
"gbrhl",
"gbro",
"gbteew",
"gbtesw",
"gbtew",
"gbtf",
"gbti",
"gbts",
"gbtsi",
"gbtsw",
"github",
"ithub",
"itrh",
"itue",
"matc",
"paypal",
"rewi",
"rswi",
"sltp",
"SWPM",
"testid",
"volta"
],
"markdownlint.config": {
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ Fixed for any bug fixes.
Security to invite users to upgrade in case of vulnerabilities.
-->

## 0.0.6 - 2023/04/17

### Added

- cheat sheet helper section on README
- wait for snippets

### Changed

- snippets with multiple search variants to avoid repetition

## 0.0.5 - 2023/04/16

### Added
Expand Down
101 changes: 72 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ The quick and easy way to create and use Testing Library with [VS Code](https://
- [Extension Manager](#extension-manager)
- [Marketplace](#marketplace)
- [Supported Languages](#supported-languages)
- [Cheat Sheet](#cheat-sheet)
- [Snippets](#snippets)
- [Import](#import)
- [User Event](#user-event)
- [Queries](#queries)
- [Regex](#regex)
- [Wait](#wait)
- [Keyboard](#keyboard)
- [Settings](#settings)
- [About](#about)
Expand Down Expand Up @@ -68,6 +70,32 @@ Open the extension manager with <kbd>ctrl</kbd>+<kbd>shift</kbd>+<kbd>X</kbd> (W

---

## Cheat Sheet

| Search Variants | Result |
| ---------------- | --------------------------------------------- |
| `getBy`... | `Element` or `Error` |
| `getAllBy`... | `Element[]` or `Error` |
| `queryBy`... | `Element` or `null` |
| `queryAllBy`... | `Element[]` or `null` |
| `findBy`... | `Promise<Element>` or `Promise<rejection>` |
| `findAllBy`... | `Promise<Element[]>` or `Promise<rejection>` |

| Search Types | Result |
| --------------------- | --------------------------------------------- |
| ...`Role` | `<div aria="role">` or [Aria Roles](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques#roles) |
| ...`LabelText` | `<label for="Text">` |
| ...`PlaceHolderText` | `<input placeholder="Text">` |
| ...`Text` | `<a href="/page">Text</a>` |
| ...`DisplayValue` | `<input value="Text">` |
| ...`AltText` | `<img alt="Text">` |
| ...`Title` | `<span title="Text">` or `<title>` |
| ...`TestId` | `<input data-testid="Id">` |

⇧ [Back to menu](#menu)

---

## Snippets

Below is a list of all available snippets and the triggers of each one. The `░` means the `TAB` jump position and `█` the final cursor position.
Expand All @@ -90,48 +118,63 @@ Below is a list of all available snippets and the triggers of each one. The `░

### Queries

| Trigger | Result |
| --------: | ---------------------------------------------------------------- |
| `gbr→` | `screen.getByRole('░id')█` |
| `gbro→` | `screen.getByRole('░id', {░})█` |
| `gbrc→` | `screen.getByRole('checkbox')█` |
| `gbrcc→` | `screen.getByRole('checkbox', { checked: ░<true\|false>} })█` |
| `gbrh→` | `screen.getByRole('heading')█` |
| `gbrhl→` | `screen.getByRole('heading', { level: ░<1\|2\|3\|4\|5\|6>} })█` |
| `gabr→` | `screen.getAllByRole('░id')█` |
| `gabro→` | `screen.getAllByRole('░id', {░})█` |
| `gbt→` | `screen.getByText(░)█` |
| `gbtf→` | `screen.getByText('░Text Match')█` |
| `gbti→` | `screen.getByText('░text match', {ignore: false})█` |
| `gbts→` | `screen.getByText('░ext Matc', {exact: false})█` |
| `gbtsi→` | `screen.getByText('░ext matc', {exact: false, ignore: false})█` |
| `gbtsw→` | `screen.getByText((content) => content.startsWith('░Text'))█` |
| `gbtesw→` | <code>screen.getByText((content, element) => {<br/>&nbsp;&nbsp;return element.tagName.toLowerCase() === '░div' && content.startsWith('░Text')<br/>})█</code> |
| `gbtew→` | `screen.getByText((content) => content.endsWith('░Match'))█` |
| `gbteew→` | <code>screen.getByText((content, element) => {<br/>&nbsp;&nbsp;return element.tagName.toLowerCase() === '░div' && content.endsWith('░Match')<br/>})█</code> |
Sorted by recommended official priority

1. Role

| Trigger | Result |
| :------- | ----------------------------------------------------------------- |
| `br→` | `screen.░getByRole('░id')█` |
| `bro→` | `screen.░getByRole('░id', {░})█` |
| `bron→` | `screen.░getByRole('░id', {name: ░})█` |
| `brc→` | `screen.░getByRole('checkbox')█` |
| `brcc→` | `screen.░getByRole('checkbox', { checked: ░<true\|false>} })█` |
| `brh→` | `screen.░getByRole('heading')█` |
| `brhl→` | `screen.░getByRole('heading', { level: ░<1\|2\|3\|4\|5\|6>} })█` |

4. Text

| Trigger | Result |
| :------- | ---------------------------------------------------------------- |
| `bt→` | `screen.░getByText(░)█` |
| `btf→` | `screen.░getByText('░Text Match')█` |
| `bti→` | `screen.░getByText('░text match', {ignore: false})█` |
| `bts→` | `screen.░getByText('░ext Matc', {exact: false})█` |
| `btsi→` | `screen.░getByText('░ext matc', {exact: false, ignore: false})█` |
| `btsw→` | `screen.░getByText((content) => content.startsWith('░Text'))█` |
| `btesw→` | <code>screen.░getByText((content, element) => {<br/>&nbsp;&nbsp;return element.tagName.toLowerCase() === '░div' && content.startsWith('░Text')<br/>})█</code> |
| `btew→` | `screen.░getByText((content) => content.endsWith('░Match'))█` |
| `bteew→` | <code>screen.░getByText((content, element) => {<br/>&nbsp;&nbsp;return element.tagName.toLowerCase() === '░div' && content.endsWith('░Match')<br/>})█</code> |

### Debug

| Trigger | Result |
| -------: | ------------------------------------ |
| `sd→` | `screen.debug()█` |
| `sltp→` | `screen.logTestingPlaygroundURL()█` |
| :------- | ------------------------------------ |
| `sd→` | `screen.debug()█` |
| `sltp→` | `screen.logTestingPlaygroundURL()█` |

### Regex

It can be used as a text matcher or `name` property on queries.

| Trigger | Description | Result |
| ------: | --------------------------- | ------------------- |
| `rf→` | full text match | `/^░Text Match$/█` |
| `rfi→` | full text match ignore case | `/^░text match$/i█` |
| `rs→` | substring match | `/░ext Matc/█` |
| `rsi→` | substring match ignore case | `/░ext matc/i█` |
| `rsw→` | start with | `/^░Text/█` |
| :------ | --------------------------- | ------------------- |
| `rf→` | full text match | `/^░Text Match$/█` |
| `rfi→` | full text match ignore case | `/^░text match$/i█` |
| `rs→` | substring match | `/░ext Matc/█` |
| `rsi→` | substring match ignore case | `/░ext matc/i█` |
| `rsw→` | start with | `/^░Text/█` |
| `rswi→` | start with ignore case | `/^░text/i█` |
| `rew→` | end with | `/░Match$/█` |
| `rew→` | end with | `/░Match$/█` |
| `rewi→` | end with ignore case | `/░match$/i█` |

### Wait

| Trigger | Result |
| :------- | ------------------------------------------------------------------------------- |
| `wf→` | <code>await waitFor(<br/>&nbsp;&nbsp;() => ░<br/>)█</code> |
| `wfr→` | <code>await waitForElementToBeRemoved(<br/>&nbsp;&nbsp;() => ░<br/>)█</code> |

⇧ [Back to menu](#menu)

---
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "testing-library-snippets",
"description": "VS Code Testing Library snippets for JS and TS",
"version": "0.0.5",
"version": "0.0.6",
"displayName": "Testing Library Snippets",
"publisher": "deinsoftware",
"icon": "images/light-icon.png",
Expand Down
Loading