Skip to content

Commit 7730a8a

Browse files
authored
Merge pull request #4 from deinsoftware/dev
added regex an getByText snippets
2 parents e3963f5 + 78e26a5 commit 7730a8a

File tree

6 files changed

+174
-11
lines changed

6 files changed

+174
-11
lines changed

.vscode/settings.json

+11
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,21 @@
1010
"gbrh",
1111
"gbrhl",
1212
"gbro",
13+
"gbteew",
14+
"gbtesw",
15+
"gbtew",
16+
"gbtf",
17+
"gbti",
18+
"gbts",
19+
"gbtsi",
20+
"gbtsw",
1321
"github",
1422
"itrh",
1523
"itue",
24+
"matc",
1625
"paypal",
26+
"rewi",
27+
"rswi",
1728
"sltp",
1829
"volta"
1930
],

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ Fixed for any bug fixes.
99
Security to invite users to upgrade in case of vulnerabilities.
1010
-->
1111

12+
## 0.0.5 - 2023/04/16
13+
14+
### Added
15+
16+
- regex snippets
17+
- getByText query snippets
18+
1219
## 0.0.4 - 2023/04/15
1320

1421
### Fixed

README.md

+35-10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ The quick and easy way to create and use Testing Library with [VS Code](https://
2323
- [Import](#import)
2424
- [User Event](#user-event)
2525
- [Queries](#queries)
26+
- [Regex](#regex)
2627
- [Keyboard](#keyboard)
2728
- [Settings](#settings)
2829
- [About](#about)
@@ -89,16 +90,25 @@ Below is a list of all available snippets and the triggers of each one. The `░
8990

9091
### Queries
9192

92-
| Trigger | Result |
93-
| -------: | ---------------------------------------------------------------- |
94-
| `gbr→` | `screen.getByRole('░id')█` |
95-
| `gbro→` | `screen.getByRole('░id', {░})█` |
96-
| `gbrc→` | `screen.getByRole('checkbox')█` |
97-
| `gbrcc→` | `screen.getByRole('checkbox', { checked: ░<true\|false>} })█` |
98-
| `gbrh→` | `screen.getByRole('heading')█` |
99-
| `gbrhl→` | `screen.getByRole('heading', { level: ░<1\|2\|3\|4\|5\|6>} })█` |
100-
| `gabr→` | `screen.getAllByRole('░id')█` |
101-
| `gabro→` | `screen.getAllByRole('░id', {░})█` |
93+
| Trigger | Result |
94+
| --------: | ---------------------------------------------------------------- |
95+
| `gbr→` | `screen.getByRole('░id')█` |
96+
| `gbro→` | `screen.getByRole('░id', {░})█` |
97+
| `gbrc→` | `screen.getByRole('checkbox')█` |
98+
| `gbrcc→` | `screen.getByRole('checkbox', { checked: ░<true\|false>} })█` |
99+
| `gbrh→` | `screen.getByRole('heading')█` |
100+
| `gbrhl→` | `screen.getByRole('heading', { level: ░<1\|2\|3\|4\|5\|6>} })█` |
101+
| `gabr→` | `screen.getAllByRole('░id')█` |
102+
| `gabro→` | `screen.getAllByRole('░id', {░})█` |
103+
| `gbt→` | `screen.getByText(░)█` |
104+
| `gbtf→` | `screen.getByText('░Text Match')█` |
105+
| `gbti→` | `screen.getByText('░text match', {ignore: false})█` |
106+
| `gbts→` | `screen.getByText('░ext Matc', {exact: false})█` |
107+
| `gbtsi→` | `screen.getByText('░ext matc', {exact: false, ignore: false})█` |
108+
| `gbtsw→` | `screen.getByText((content) => content.startsWith('░Text'))█` |
109+
| `gbtesw→` | <code>screen.getByText((content, element) => {<br/>&nbsp;&nbsp;return element.tagName.toLowerCase() === '░div' && content.startsWith('░Text')<br/>})█</code> |
110+
| `gbtew→` | `screen.getByText((content) => content.endsWith('░Match'))█` |
111+
| `gbteew→` | <code>screen.getByText((content, element) => {<br/>&nbsp;&nbsp;return element.tagName.toLowerCase() === '░div' && content.endsWith('░Match')<br/>})█</code> |
102112

103113
### Debug
104114

@@ -107,6 +117,21 @@ Below is a list of all available snippets and the triggers of each one. The `░
107117
| `sd→` | `screen.debug()█` |
108118
| `sltp→` | `screen.logTestingPlaygroundURL()█` |
109119

120+
### Regex
121+
122+
It can be used as a text matcher or `name` property on queries.
123+
124+
| Trigger | Description | Result |
125+
| ------: | --------------------------- | ------------------- |
126+
| `rf→` | full text match | `/^░Text Match$/█` |
127+
| `rfi→` | full text match ignore case | `/^░text match$/i█` |
128+
| `rs→` | substring match | `/░ext Matc/█` |
129+
| `rsi→` | substring match ignore case | `/░ext matc/i█` |
130+
| `rsw→` | start with | `/^░Text/█` |
131+
| `rswi→` | start with ignore case | `/^░text/i█` |
132+
| `rew→` | end with | `/░Match$/█` |
133+
| `rewi→` | end with ignore case | `/░match$/i█` |
134+
110135
[Back to menu](#menu)
111136

112137
---

package.json

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "testing-library-snippets",
33
"description": "VS Code Testing Library snippets for JS and TS",
4-
"version": "0.0.4",
4+
"version": "0.0.5",
55
"displayName": "Testing Library Snippets",
66
"publisher": "deinsoftware",
77
"icon": "images/light-icon.png",
@@ -58,6 +58,10 @@
5858
"language": "javascript",
5959
"path": "./snippets/debug.json"
6060
},
61+
{
62+
"language": "javascript",
63+
"path": "./snippets/regex.json"
64+
},
6165
{
6266
"language": "javascriptreact",
6367
"path": "./snippets/import.json"
@@ -74,6 +78,10 @@
7478
"language": "javascriptreact",
7579
"path": "./snippets/debug.json"
7680
},
81+
{
82+
"language": "javascriptreact",
83+
"path": "./snippets/regex.json"
84+
},
7785
{
7886
"language": "vue",
7987
"path": "./snippets/import.json"
@@ -90,6 +98,10 @@
9098
"language": "vue",
9199
"path": "./snippets/debug.json"
92100
},
101+
{
102+
"language": "vue",
103+
"path": "./snippets/regex.json"
104+
},
93105
{
94106
"language": "typescript",
95107
"path": "./snippets/import.json"
@@ -106,6 +118,10 @@
106118
"language": "typescript",
107119
"path": "./snippets/debug.json"
108120
},
121+
{
122+
"language": "typescript",
123+
"path": "./snippets/regex.json"
124+
},
109125
{
110126
"language": "typescriptreact",
111127
"path": "./snippets/import.json"
@@ -118,6 +134,10 @@
118134
"language": "typescriptreact",
119135
"path": "./snippets/queries.json"
120136
},
137+
{
138+
"language": "typescriptreact",
139+
"path": "./snippets/debug.json"
140+
},
121141
{
122142
"language": "typescriptreact",
123143
"path": "./snippets/debug.json"

snippets/queries.json

+58
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,63 @@
3838
"prefix": "gabro",
3939
"body": ["screen.getAllByRole('${1:id}', {$2})$0"],
4040
"description": "getAllByRole query with options"
41+
},
42+
43+
"getBy.text": {
44+
"prefix": "gbt",
45+
"body": ["screen.getByText($1)$0"],
46+
"description": "getByText query"
47+
},
48+
"getBy.text.full": {
49+
"prefix": "gbtf",
50+
"body": ["screen.getByText('${1:Text Match}')$0"],
51+
"description": "getByText query full string match"
52+
},
53+
"getBy.text.ignore": {
54+
"prefix": "gbti",
55+
"body": ["screen.getByText('${1:text match}', {ignore: false})$0"],
56+
"description": "getByText query full string ignore case"
57+
},
58+
"getBy.text.substring": {
59+
"prefix": "gbts",
60+
"body": ["screen.getByText('${1:ext Matc}', {exact: false})$0"],
61+
"description": "getByText query substring match"
62+
},
63+
"getBy.text.substring+ignore": {
64+
"prefix": "gbtsi",
65+
"body": [
66+
"screen.getByText('${1:ext matc}', {exact: false, ignore: false})$0"
67+
],
68+
"description": "getByText query substring match ignore case"
69+
},
70+
"getBy.text.startWith": {
71+
"prefix": "gbtsw",
72+
"body": [
73+
"screen.getByText((content) => content.startsWith('${1:Text}'))$0"
74+
],
75+
"description": "getByText query start with match"
76+
},
77+
"getBy.text.element.startWith": {
78+
"prefix": "gbtesw",
79+
"body": [
80+
"screen.getByText((content, element) => {",
81+
"\treturn element.tagName.toLowerCase() === '${1:div}' && content.startsWith('${2:Text}')",
82+
"})"
83+
],
84+
"description": "getByText query start with match on specific element"
85+
},
86+
"getBy.text.endWith": {
87+
"prefix": "gbtew",
88+
"body": ["screen.getByText((content) => content.endsWith('${1:Match}'))$0"],
89+
"description": "getByText query end with match"
90+
},
91+
"getBy.text.element.endWith": {
92+
"prefix": "gbteew",
93+
"body": [
94+
"screen.getByText((content, element) => {",
95+
"\treturn element.tagName.toLowerCase() === '${1:div}' && content.endsWith('${1:Match}')",
96+
"})"
97+
],
98+
"description": "getByText query end with match on specific element"
4199
}
42100
}

snippets/regex.json

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"regex.full": {
3+
"prefix": "rf",
4+
"body": ["/^${1:Text Match}$/$0"],
5+
"description": "regex full string match"
6+
},
7+
"regex.full+ignore": {
8+
"prefix": "rfi",
9+
"body": ["/^${1:text match}$/i$0"],
10+
"description": "regex full string match and ignore case"
11+
},
12+
"regex.substring": {
13+
"prefix": "rs",
14+
"body": ["/${1:ext Matc}/$0"],
15+
"description": "regex substring match"
16+
},
17+
"regex.substring+ignore": {
18+
"prefix": "rsi",
19+
"body": ["/${1:ext matc}/i$0"],
20+
"description": "regex substring match and ignore case"
21+
},
22+
"regex.start": {
23+
"prefix": "rsw",
24+
"body": ["/^${1:Text}/$0"],
25+
"description": "regex start with string match"
26+
},
27+
"regex.start+ignore": {
28+
"prefix": "rswi",
29+
"body": ["/^${1:text}/i$0"],
30+
"description": "regex start with string match and ignore case"
31+
},
32+
"regex.end": {
33+
"prefix": "rew",
34+
"body": ["/${1:Match}$/$0"],
35+
"description": "regex end with string match"
36+
},
37+
"regex.end+ignore": {
38+
"prefix": "rewi",
39+
"body": ["/${1:match}$/i$0"],
40+
"description": "regex end with string match and ignore case"
41+
}
42+
}

0 commit comments

Comments
 (0)