Skip to content

Commit 2a15f1c

Browse files
authored
Merge pull request #12 from deinsoftware/dev
add mock, import with extras and expect any type
2 parents bc3bfe2 + 173a20d commit 2a15f1c

File tree

8 files changed

+118
-21
lines changed

8 files changed

+118
-21
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"cSpell.words": [
33
"cfrv",
44
"deinsoftware",
5+
"eatg",
56
"Equiman",
67
"github",
78
"mrvo",

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ Fixed for any bug fixes.
99
Security to invite users to upgrade in case of vulnerabilities.
1010
-->
1111

12+
## 1.6.0 - 2023/04/04
13+
14+
### Added
15+
16+
- expect any TypeScript
17+
- afterEach mock clear and reset
18+
- extra imports for vitest
19+
- vi.mock
20+
1221
## 1.5.1 - 2023/04/04
1322

1423
### Fixed

README.md

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ The quick and easy way to create and use Vitest with [VS Code](https://code.visu
2727
- [It](#it)
2828
- [Test](#test)
2929
- [Expect](#expect)
30+
- [Any](#any)
3031
- [Assertion](#assertion)
3132
- [Keyboard](#keyboard)
3233
- [Settings](#settings)
@@ -78,20 +79,21 @@ Below is a list of all available snippets and the triggers of each one. The `░
7879

7980
### Import
8081

81-
| Trigger | Result |
82-
| -------: | ----------------------------------------------------------------- |
83-
| `iv→` | `import { it, expect, describe } from 'vitest'█` |
82+
| Trigger | Result |
83+
| -------: | ---------------------------------------------------------------------------- |
84+
| `iv→` | `import { it, expect, describe } from 'vitest'█` |
85+
| `ive→` | `import { beforeEach, afterEach, it, expect, describe, vi } from 'vitest'█` |
8486

8587
### Setup
8688

8789
| Trigger | Result |
8890
| -------: | --------------------------------------------------------------- |
89-
| `ae→` | <code>afterEach(() => {<br/>&nbsp;&nbsp;█<br/>})</code> |
90-
| `aa→` | <code>afterAll(() => {<br/>&nbsp;&nbsp;█<br/>})</code> |
91-
| `be→` | <code>beforeEach(() => {<br/>&nbsp;&nbsp;█<br/>})</code> |
92-
| `bea→` | <code>beforeEach(async () => {<br/>&nbsp;&nbsp;█<br/>})</code> |
9391
| `ba→` | <code>beforeAll(() => {<br/>&nbsp;&nbsp;█<br/>})</code> |
9492
| `baa→` | <code>beforeAll(async () => {<br/>&nbsp;&nbsp;█<br/>})</code> |
93+
| `be→` | <code>beforeEach(() => {<br/>&nbsp;&nbsp;█<br/>})</code> |
94+
| `bea→` | <code>beforeEach(async () => {<br/>&nbsp;&nbsp;█<br/>})</code> |
95+
| `ae→` | <code>afterEach(() => {<br/>&nbsp;&nbsp;█<br/>})</code> |
96+
| `aa→` | <code>afterAll(() => {<br/>&nbsp;&nbsp;█<br/>})</code> |
9597

9698
### Describe
9799

@@ -104,18 +106,21 @@ Below is a list of all available snippets and the triggers of each one. The `░
104106

105107
### Mock
106108

107-
| Trigger | Result |
108-
| -------: | ------------------------------------------------------------------------------ |
109-
| `vf→` | `vi.fn()█` |
110-
| `vfrv→` | `vi.fn().mockResolvedValue(█)` |
111-
| `cf→` | `const ░nameMock = vi.fn()█` |
112-
| `cfrv→` | `const ░nameMock = vi.fn().mockResolvedValue(█)` |
113-
| `mrv→` | `░mock.mockReturnValue(█)` |
114-
| `mrvo→` | `░mock.mockReturnValueOnce(█)` |
115-
| `vs→` | `vi.spyOn(░global, '░method')█` |
116-
| `vsi→` | `vi.spyOn(░global, '░method').mockImplementation(() => █)` |
117-
| `cs→` | `const ░methodSpy = vi.spyOn(░global, '░method')█` |
118-
| `csi→` | `const ░methodSpy = vi.spyOn(░global, '░method').mockImplementation(() => █)` |
109+
| Trigger | Result |
110+
| -------: | ------------------------------------------------------------------------------------------------------------- |
111+
| `aevcr→` | <code>afterEach(() => {<br/>&nbsp;&nbsp;vi.clearAllMocks()<br/>&nbsp;&nbsp;vi.resetAllMocks()<br/>})█</code> |
112+
| `vm→` | `vi.mock('░path')█` |
113+
| `vmrv→` | `vi.mock('░path').mockResolvedValue(█)` |
114+
| `vf→` | `vi.fn()█` |
115+
| `vfrv→` | `vi.fn().mockResolvedValue(█)` |
116+
| `cf→` | `const ░nameMock = vi.fn()█` |
117+
| `cfrv→` | `const ░nameMock = vi.fn().mockResolvedValue(█)` |
118+
| `mrv→` | `░mock.mockReturnValue(█)` |
119+
| `mrvo→` | `░mock.mockReturnValueOnce(█)` |
120+
| `vs→` | `vi.spyOn(░global, '░method')█` |
121+
| `vsi→` | `vi.spyOn(░global, '░method').mockImplementation(() => █)` |
122+
| `cs→` | `const ░methodSpy = vi.spyOn(░global, '░method')█` |
123+
| `csi→` | `const ░methodSpy = vi.spyOn(░global, '░method').mockImplementation(() => █)` |
119124

120125
### It
121126

@@ -146,7 +151,20 @@ Below is a list of all available snippets and the triggers of each one. The `░
146151
| `ea→` | `expect.assertions(█)` |
147152
| `eha→` | `expect.hasAssertions()█` |
148153
| `erj→` | `expect(░).rejects█` |
149-
| `ers→` | `expect(░).resolves█` |
154+
| `ers→` | `expect(░).resolves█` |
155+
156+
### Any
157+
158+
| Trigger | Result |
159+
| -------: | ------------------------ |
160+
| `eav→` | `expect.any(░)█` |
161+
| `eas→` | `expect.any(String)█` |
162+
| `ean→` | `expect.any(Number)█` |
163+
| `eab→` | `expect.any(Boolean)█` |
164+
| `ead→` | `expect.any(Date)█` |
165+
| `eaf→` | `expect.any(Function)█` |
166+
| `eaa→` | `expect.any(Array)█` |
167+
| `eat→` | `expect.anything()█` |
150168

151169
### Assertion
152170

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vitest-snippets",
33
"description": "VS Code Vitest snippets for JS and TS",
4-
"version": "1.5.1",
4+
"version": "1.6.0",
55
"displayName": "Vitest Snippets",
66
"publisher": "deinsoftware",
77
"icon": "images/light-icon.png",

snippets/import.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,10 @@
33
"prefix": "iv",
44
"body": "import { it, expect, describe } from 'vitest'$0",
55
"description": "essential imports for vitest"
6+
},
7+
"import.vitest.extra": {
8+
"prefix": "ive",
9+
"body": "import { beforeEach, afterEach, it, expect, describe, vi } from 'vitest'$0",
10+
"description": "extra imports for vitest"
611
}
712
}

snippets/mock.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
11
{
2+
"vi.afterEach.mockClearReset": {
3+
"prefix": "aevcr",
4+
"body": [
5+
"afterEach(() => {",
6+
"\tvi.clearAllMocks()",
7+
"\tvi.resetAllMocks()",
8+
"})$0"
9+
],
10+
"description": "afterEach mock clear and reset functions called once after each spec"
11+
},
12+
"vi.mock": {
13+
"prefix": "vm",
14+
"body": "vi.mock('${1:path}')$0",
15+
"description": "creates vi.mock()"
16+
},
17+
"vi.mock.mockResolvedValue": {
18+
"prefix": "vmrv",
19+
"body": "vi.mock('${1:path}').mockResolvedValue($0)",
20+
"description": "creates vi.mock() with resolved value"
21+
},
222
"vi.fn": {
323
"prefix": "vf",
424
"body": "vi.fn()$0",

snippets/type.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"expect.any.type": {
3+
"prefix": "eav",
4+
"body": "expect.any($1)$0",
5+
"description": "expect any value type"
6+
},
7+
"expect.any.string": {
8+
"prefix": "eas",
9+
"body": "expect.any(String)$0",
10+
"description": "expect any string type"
11+
},
12+
"expect.any.number": {
13+
"prefix": "ean",
14+
"body": "expect.any(Number)$0",
15+
"description": "expect any number type"
16+
},
17+
"expect.any.boolean": {
18+
"prefix": "eab",
19+
"body": "expect.any(Boolean)$0",
20+
"description": "expect any boolean type"
21+
},
22+
"expect.any.date": {
23+
"prefix": "ead",
24+
"body": "expect.any(Date)$0",
25+
"description": "expect any date type"
26+
},
27+
"expect.any.function": {
28+
"prefix": "eaf",
29+
"body": "expect.any(Function)$0",
30+
"description": "expect any function type"
31+
},
32+
"expect.any.array": {
33+
"prefix": "eaa",
34+
"body": "expect.any(Array)$0",
35+
"description": "expect any array type"
36+
},
37+
"expect.any.thing": {
38+
"prefix": "eat",
39+
"body": "expect.anything()$0",
40+
"description": "expect anything"
41+
}
42+
}

test/snippets.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const itSnippets = require("../snippets/it.json")
88
const testSnippets = require("../snippets/test.json")
99
const expectSnippets = require("../snippets/expect.json")
1010
const assertionSnippets = require("../snippets/assertion.json")
11+
const typeSnippets = require("../snippets/type.json")
1112

1213
const snippets = {
1314
...importSnippets,
@@ -18,6 +19,7 @@ const snippets = {
1819
...testSnippets,
1920
...expectSnippets,
2021
...assertionSnippets,
22+
...typeSnippets,
2123
}
2224

2325
const unique = (xs) => [...new Set(xs)]

0 commit comments

Comments
 (0)