Skip to content

Commit

Permalink
Merge pull request #12 from deinsoftware/dev
Browse files Browse the repository at this point in the history
add mock, import with extras and expect any type
  • Loading branch information
equiman authored Apr 5, 2023
2 parents bc3bfe2 + 173a20d commit 2a15f1c
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 21 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"cSpell.words": [
"cfrv",
"deinsoftware",
"eatg",
"Equiman",
"github",
"mrvo",
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ Fixed for any bug fixes.
Security to invite users to upgrade in case of vulnerabilities.
-->

## 1.6.0 - 2023/04/04

### Added

- expect any TypeScript
- afterEach mock clear and reset
- extra imports for vitest
- vi.mock

## 1.5.1 - 2023/04/04

### Fixed
Expand Down
58 changes: 38 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The quick and easy way to create and use Vitest with [VS Code](https://code.visu
- [It](#it)
- [Test](#test)
- [Expect](#expect)
- [Any](#any)
- [Assertion](#assertion)
- [Keyboard](#keyboard)
- [Settings](#settings)
Expand Down Expand Up @@ -78,20 +79,21 @@ Below is a list of all available snippets and the triggers of each one. The `░

### Import

| Trigger | Result |
| -------: | ----------------------------------------------------------------- |
| `iv→` | `import { it, expect, describe } from 'vitest'█` |
| Trigger | Result |
| -------: | ---------------------------------------------------------------------------- |
| `iv→` | `import { it, expect, describe } from 'vitest'█` |
| `ive→` | `import { beforeEach, afterEach, it, expect, describe, vi } from 'vitest'█` |

### Setup

| Trigger | Result |
| -------: | --------------------------------------------------------------- |
| `ae→` | <code>afterEach(() => {<br/>&nbsp;&nbsp;█<br/>})</code> |
| `aa→` | <code>afterAll(() => {<br/>&nbsp;&nbsp;█<br/>})</code> |
| `be→` | <code>beforeEach(() => {<br/>&nbsp;&nbsp;█<br/>})</code> |
| `bea→` | <code>beforeEach(async () => {<br/>&nbsp;&nbsp;█<br/>})</code> |
| `ba→` | <code>beforeAll(() => {<br/>&nbsp;&nbsp;█<br/>})</code> |
| `baa→` | <code>beforeAll(async () => {<br/>&nbsp;&nbsp;█<br/>})</code> |
| `be→` | <code>beforeEach(() => {<br/>&nbsp;&nbsp;█<br/>})</code> |
| `bea→` | <code>beforeEach(async () => {<br/>&nbsp;&nbsp;█<br/>})</code> |
| `ae→` | <code>afterEach(() => {<br/>&nbsp;&nbsp;█<br/>})</code> |
| `aa→` | <code>afterAll(() => {<br/>&nbsp;&nbsp;█<br/>})</code> |

### Describe

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

### Mock

| 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(() => █)` |
| Trigger | Result |
| -------: | ------------------------------------------------------------------------------------------------------------- |
| `aevcr→` | <code>afterEach(() => {<br/>&nbsp;&nbsp;vi.clearAllMocks()<br/>&nbsp;&nbsp;vi.resetAllMocks()<br/>})█</code> |
| `vm→` | `vi.mock('░path')█` |
| `vmrv→` | `vi.mock('░path').mockResolvedValue(█)` |
| `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 Expand Up @@ -146,7 +151,20 @@ Below is a list of all available snippets and the triggers of each one. The `░
| `ea→` | `expect.assertions(█)` |
| `eha→` | `expect.hasAssertions()█` |
| `erj→` | `expect(░).rejects█` |
| `ers→` | `expect(░).resolves█` |
| `ers→` | `expect(░).resolves█` |

### Any

| Trigger | Result |
| -------: | ------------------------ |
| `eav→` | `expect.any(░)█` |
| `eas→` | `expect.any(String)█` |
| `ean→` | `expect.any(Number)█` |
| `eab→` | `expect.any(Boolean)█` |
| `ead→` | `expect.any(Date)█` |
| `eaf→` | `expect.any(Function)█` |
| `eaa→` | `expect.any(Array)█` |
| `eat→` | `expect.anything()█` |

### Assertion

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.5.1",
"version": "1.6.0",
"displayName": "Vitest Snippets",
"publisher": "deinsoftware",
"icon": "images/light-icon.png",
Expand Down
5 changes: 5 additions & 0 deletions snippets/import.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
"prefix": "iv",
"body": "import { it, expect, describe } from 'vitest'$0",
"description": "essential imports for vitest"
},
"import.vitest.extra": {
"prefix": "ive",
"body": "import { beforeEach, afterEach, it, expect, describe, vi } from 'vitest'$0",
"description": "extra imports for vitest"
}
}
20 changes: 20 additions & 0 deletions snippets/mock.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
{
"vi.afterEach.mockClearReset": {
"prefix": "aevcr",
"body": [
"afterEach(() => {",
"\tvi.clearAllMocks()",
"\tvi.resetAllMocks()",
"})$0"
],
"description": "afterEach mock clear and reset functions called once after each spec"
},
"vi.mock": {
"prefix": "vm",
"body": "vi.mock('${1:path}')$0",
"description": "creates vi.mock()"
},
"vi.mock.mockResolvedValue": {
"prefix": "vmrv",
"body": "vi.mock('${1:path}').mockResolvedValue($0)",
"description": "creates vi.mock() with resolved value"
},
"vi.fn": {
"prefix": "vf",
"body": "vi.fn()$0",
Expand Down
42 changes: 42 additions & 0 deletions snippets/type.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"expect.any.type": {
"prefix": "eav",
"body": "expect.any($1)$0",
"description": "expect any value type"
},
"expect.any.string": {
"prefix": "eas",
"body": "expect.any(String)$0",
"description": "expect any string type"
},
"expect.any.number": {
"prefix": "ean",
"body": "expect.any(Number)$0",
"description": "expect any number type"
},
"expect.any.boolean": {
"prefix": "eab",
"body": "expect.any(Boolean)$0",
"description": "expect any boolean type"
},
"expect.any.date": {
"prefix": "ead",
"body": "expect.any(Date)$0",
"description": "expect any date type"
},
"expect.any.function": {
"prefix": "eaf",
"body": "expect.any(Function)$0",
"description": "expect any function type"
},
"expect.any.array": {
"prefix": "eaa",
"body": "expect.any(Array)$0",
"description": "expect any array type"
},
"expect.any.thing": {
"prefix": "eat",
"body": "expect.anything()$0",
"description": "expect anything"
}
}
2 changes: 2 additions & 0 deletions test/snippets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const itSnippets = require("../snippets/it.json")
const testSnippets = require("../snippets/test.json")
const expectSnippets = require("../snippets/expect.json")
const assertionSnippets = require("../snippets/assertion.json")
const typeSnippets = require("../snippets/type.json")

const snippets = {
...importSnippets,
Expand All @@ -18,6 +19,7 @@ const snippets = {
...testSnippets,
...expectSnippets,
...assertionSnippets,
...typeSnippets,
}

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

0 comments on commit 2a15f1c

Please sign in to comment.