Skip to content

Commit

Permalink
Merge pull request #2 from deinsoftware/dev
Browse files Browse the repository at this point in the history
add better mock and spy snippets
  • Loading branch information
equiman authored Feb 27, 2023
2 parents d2479fd + 57e683b commit dbb2721
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"cSpell.words": [
"cfrv",
"deinsoftware",
"Equiman",
"github",
"mrvo",
"paypal",
"tbct",
"tbgt",
Expand All @@ -16,6 +18,7 @@
"tmis",
"ttemis",
"ttems",
"vfrv",
"volta"
],
"markdownlint.config": {
Expand Down
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.
-->

## 1.1.0 - 2023/02/26

### Added

- Better mock and spy snippets

## 1.0.0 - 2023/02/26

### Added
Expand Down
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,18 @@ Below is a list of all available snippets and the triggers of each one. The **

### Mock

| Trigger | Result |
| -------: | ------------- |
| `vf→` | `vi.fn(█)` |
| `vs→` | `vi.spyOn(█)` |
| Trigger | Result |
| -------: | --------------------------------------------------------------------------- |
| `vf→` | `vi.fn()█` |
| `vfrv→` | `vi.fn().mockResolvedValue(█)` |
| `cf→` | `const nameMock = vi.fn()█` |
| `cfrv→` | `const nameMock = vi.fn().mockResolvedValue(█)` |
| `mrv→` | `mock.mockReturnValue(█)` |
| `mrvo→` | `mock.mockReturnValueOnce(█)` |
| `vs→` | `vi.spyOn(global, 'method')█` |
| `vsi→` | `vi.spyOn(global, 'method').mockImplementation(() => █)` |
| `cs→` | `const methodSpy = vi.spyOn(global, 'method')█` |
| `csi→` | `const methodSpy = vi.spyOn(global, 'method').mockImplementation(() => █)` |

### It

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": "vitest-snippets",
"description": "VS Code Vitest snippets for JS and TS",
"version": "1.0.0",
"version": "1.1.0",
"displayName": "Vitest Snippets",
"publisher": "deinsoftware",
"icon": "images/light-icon.png",
Expand Down
44 changes: 42 additions & 2 deletions snippets/mock.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,52 @@
{
"vi.fn": {
"prefix": "vf",
"body": "vi.fn($0)",
"body": "vi.fn()$0",
"description": "creates vi.fn()"
},
"vi.fn.mockResolvedValue": {
"prefix": "vfrv",
"body": "vi.fn().mockResolvedValue($0)",
"description": "creates vi.fn() with resolved value"
},
"const.fn": {
"prefix": "cf",
"body": "const {$1:name}Mock = vi.fn()$0",
"description": "creates a mock variable for a vi.fn()"
},
"const.fn.mockResolvedValue": {
"prefix": "cfrv",
"body": "const {$1:name}Mock = vi.fn().mockResolvedValue($0)",
"description": "creates a mock variable for a vi.fn() with resolved value"
},
"mock.mockReturnValue": {
"prefix": "mrv",
"body": "{$1:mock}.mockReturnValue($0)",
"description": "assign a return value"
},
"mock.mockReturnValueOnce": {
"prefix": "mrv",
"body": "{$1:mock}.mockReturnValueOnce($0)",
"description": "assign a return value for only one call"
},
"vi.spyOn": {
"prefix": "vs",
"body": "vi.spyOn($0)",
"body": "vi.spyOn({$1:global}, '{$2:method}'))$0",
"description": "creates vi.spyOn()"
},
"vi.spyOn.mockImplementation": {
"prefix": "vsi",
"body": "vi.spyOn({$1:global}, '{$2:method}')).mockImplementation(() => $0)",
"description": "creates vi.spyOn() with mock implementation"
},
"const.spyOn": {
"prefix": "cs",
"body": "const {$2:method}Spy = vi.spyOn({$1:global}, '{$2:method}'))$0",
"description": "creates a spy variable for a vi.spyOn()"
},
"const.spyOn.mockImplementation": {
"prefix": "csi",
"body": "const {$2:method}Spy = vi.spyOn({$1:global}, '{$2:method}')).mockImplementation(() => $0)",
"description": "creates a spy variable for a vi.spyOn() with mock implementation"
}
}

0 comments on commit dbb2721

Please sign in to comment.