Skip to content
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ Fixed for any bug fixes.
Security to invite users to upgrade in case of vulnerabilities.
-->

## 0.0.8 - 2023/04/18

### Changed

- Cheat sheet based on official documentation

## 0.0.7 - 2023/04/17

### Fixed
Expand Down
50 changes: 29 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,35 @@ 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">` |
You can write any combination of Search variants and Search types.

### Search variants

| Variants | Return if no match | Return if 1 match | Return if 1+ match | Await? |
| --------------- | ------------------ | ----------------- | ------------------ | ------ |
| `getBy`... | throw | return | throw | No |
| `getAllBy`... | throw | array | array | No |
| `queryBy`... | `null` | return | throw | No |
| `queryAllBy`... | `[]` | array | array | No |
| `findBy`... | throw | return | throw | Yes |
| `findAllBy`... | throw | array | array | Yes |

### Search types

Sorted by oficial recommended [order of priority](https://testing-library.com/docs/queries/about/#priority).

| | Types | finds by... | DOM example |
| - | --------------------- | -------------------------------- | ------------------------------------- |
| 1 | ...,`Role` | [ARIA role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques#roles) | `<div role="dialog" />` |
| 2 | ...,`LabelText` | label or aria-label content | `<label for="element" />` |
| 3 | ...,`PlaceholderText` | input placeholder value | `<input placeholder="name" />` |
| 4 | ...,`Text` | element text content | `<p>Lorem ipsum</p>` |
| 5 | ...,`DisplayValue` | form element current value | `<input value="Current Value">` |
| 6 | ...,`AltText` | img alt attribute | `<img alt="movie poster" />` |
| 7 | ...,`Title` | title attribute or svg title tag | `<span title="Add" />` or `<title />` |
| 8 | ...,`TestId` | data-testid attribute | `<div data-testid="some-message" />` |

> For more information visit the oficial cheat sheet: [DOM](https://testing-library.com/docs/dom-testing-library/cheatsheet) - [React](https://testing-library.com/docs/react-testing-library/cheatsheet) - [Vue](https://testing-library.com/docs/vue-testing-library/cheatsheet)

⇧ [Back to menu](#menu)

Expand Down Expand Up @@ -118,8 +128,6 @@ Below is a list of all available snippets and the triggers of each one. The `░

### Queries

Sorted by recommended official priority

#### 1. Role

| Trigger | Result |
Expand Down
24 changes: 22 additions & 2 deletions 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.7",
"version": "0.0.8",
"displayName": "Testing Library Snippets",
"publisher": "deinsoftware",
"icon": "images/light-icon.png",
Expand Down Expand Up @@ -62,6 +62,10 @@
"language": "javascript",
"path": "./snippets/regex.json"
},
{
"language": "javascript",
"path": "./snippets/wait.json"
},
{
"language": "javascriptreact",
"path": "./snippets/import.json"
Expand All @@ -82,6 +86,10 @@
"language": "javascriptreact",
"path": "./snippets/regex.json"
},
{
"language": "javascriptreact",
"path": "./snippets/wait.json"
},
{
"language": "vue",
"path": "./snippets/import.json"
Expand All @@ -102,6 +110,10 @@
"language": "vue",
"path": "./snippets/regex.json"
},
{
"language": "vue",
"path": "./snippets/wait.json"
},
{
"language": "typescript",
"path": "./snippets/import.json"
Expand All @@ -122,6 +134,10 @@
"language": "typescript",
"path": "./snippets/regex.json"
},
{
"language": "typescript",
"path": "./snippets/wait.json"
},
{
"language": "typescriptreact",
"path": "./snippets/import.json"
Expand All @@ -140,7 +156,11 @@
},
{
"language": "typescriptreact",
"path": "./snippets/debug.json"
"path": "./snippets/regex.json"
},
{
"language": "typescriptreact",
"path": "./snippets/wait.json"
}
]
},
Expand Down