Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/deinsoftware/vscode-vitest-snippets

VS Code Vitest snippets for JS and TS
https://github.com/deinsoftware/vscode-vitest-snippets

hacktoberfest javascript node nodejs react reactjs snippets snippets-collection typescript visual-studio-code vscode vscode-extension vue vuejs

Last synced: 11 days ago
JSON representation

VS Code Vitest snippets for JS and TS

Awesome Lists containing this project

README

        

# Vitest Snippets

[![Version](https://img.shields.io/visual-studio-marketplace/v/deinsoftware.vitest-snippets.svg)](https://marketplace.visualstudio.com/items?itemName=deinsoftware.vitest-snippets)
[![Installs](https://img.shields.io/visual-studio-marketplace/i/deinsoftware.vitest-snippets.svg)](https://marketplace.visualstudio.com/items?itemName=deinsoftware.vitest-snippets)
[![Ratings](https://img.shields.io/visual-studio-marketplace/stars/deinsoftware.vitest-snippets.svg)](https://marketplace.visualstudio.com/items?itemName=deinsoftware.vitest-snippets)
[![license](https://img.shields.io/github/license/deinsoftware/vscode-vitest-snippets)](LICENSE.md)
[![Open in VS Code](https://img.shields.io/static/v1?logo=visualstudiocode&label=&message=Open%20in%20Visual%20Studio%20Code&labelColor=2c2c32&color=007acc&logoColor=007acc)](https://open.vscode.dev/deinsoftware/vscode-vitest-snippets)

![Vitest](https://raw.githubusercontent.com/deinsoftware/vscode-vitest-snippets/main/.github/social/preview.png)

The quick and easy way to create and use Vitest with [VS Code](https://code.visualstudio.com/).

> We also **recommend** installing his complement extension [Testing Library Snippets](https://marketplace.visualstudio.com/items?itemName=deinsoftware.testing-library-snippets)

## Menu

- [Installation](#installation)
- [Quick Launch](#quick-launch)
- [Extension Manager](#extension-manager)
- [Marketplace](#marketplace)
- [Supported Languages](#supported-languages)
- [Snippets](#snippets)
- [Import](#import)
- [Setup](#setup)
- [Describe](#describe)
- [Mock](#mock)
- [It](#it)
- [Test](#test)
- [Expect](#expect)
- [Any](#any)
- [Assertion](#assertion)
- [Skeleton](#skeleton)
- [Keyboard](#keyboard)
- [Settings](#settings)
- [About](#about)

---

## Installation

### Quick Launch

Open the quick launch with ctrl+shift+P (Win/Linux) or cmd+shift+P (macOS).

Paste the following command and press `Enter`:

```shell
ext install deinsoftware.vitest-snippets
```

### Extension Manager

Open the extension manager with ctrl+shift+X (Win/Linux) or cmd+shift+X (macOS), search for `Vitest Snippets` and click on `[Install]` button.

### Marketplace

[Vitest Snippets](https://marketplace.visualstudio.com/items?itemName=deinsoftware.vitest-snippets)

⇧ [Back to menu](#menu)

---

## Supported Languages

| Language | Extension |
| ---------------- | --------- |
| JavaScript | `.js` |
| TypeScript | `.ts` |
| JavaScript React | `.jsx` |
| TypeScript React | `.tsx` |
| Vue | `.vue` |

⇧ [Back to menu](#menu)

---

## Snippets

Below is a list of all available snippets and the triggers of each one. The `░` means the `TAB` jump position and `█` the final cursor position.

### Import

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

### Setup

| Trigger | Result |
| -------: | --------------------------------------------------------------- |
| `ba→` | beforeAll(() => {
  █
})
|
| `baa→` | beforeAll(async () => {
  █
})
|
| `be→` | beforeEach(() => {
  █
})
|
| `bea→` | beforeEach(async () => {
  █
})
|
| `ae→` | afterEach(() => {
  █
})
|
| `aa→` | afterAll(() => {
  █
})
|

### Describe

| Trigger | Result |
| -------: | ---------------------------------------------------------------------- |
| `d→` | describe('░group', () => {
  █
})
|
| `desc→` | describe('░group', () => {
  █
})
|
| `do→` | describe.only('░group', () => {
  █
})
|
| `ds→` | describe.skip('░group', () => {
  █
})
|

### Mock

| Trigger | Result |
| -------: | ------------------------------------------------------------------------------------------------------------- |
| `aevcr→` | afterEach(() => {
  vi.clearAllMocks()
  vi.resetAllMocks()
})█
|
| `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

| Trigger | Result |
| -------: | ------------------------------------------------------------------ |
| `i→` | it('░should', () => {
  █
})
|
| `it→` | it('░should', () => {
  █
})
|
| `io→` | it.only('░should', () => {
  █
})
|
| `is→` | it.skip('░should', () => {
  █
})
|
| `itd→` | `it.todo('░should')█` |
| `ia→` | it('░should', async () => {
  █
})
|

### Test

| Trigger | Result |
| -------: | ------------------------------------------------------------------- |
| `t→` | test('░should', () => {
  █
})
|
| `to→` | test.only('░should', () => {
  █
})
|
| `ts→` | test.skip('░should', () => {
  █
})
|
| `ttd→` | `test.todo('░should')█` |
| `ta→` | test('░should', async () => {
  █
})
|

### Expect

| Trigger | Result |
| -------: | -------------------------- |
| `e→` | `expect(█)` |
| `ea→` | `expect.assertions(█)` |
| `eha→` | `expect.hasAssertions()█` |
| `erj→` | `expect(░).rejects█` |
| `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

| Trigger | Result |
| --------: | ------------------------------------------------------------------------------------------- |
| `tb→` | `expect(░).toBe(░)█` |
| `tbct→` | `expect(░).toBeCloseTo(░number, ░delta)█` |
| `tbd→` | `expect(░).toBeDefined()█` |
| `tbf→` | `expect(░).toBeFalsy()█` |
| `tbgt→` | `expect(░).toBeGreaterThan(░)█` |
| `tbgte→` | `expect(░).toBeGreaterThanOrEqual(░)█` |
| `tbid→` | `expect(░).toBeInTheDocument()█` |
| `tbi→` | `expect(░).toBeInstanceOf(░)█` |
| `tblt→` | `expect(░).toBeLessThan(░)█` |
| `tblte→` | `expect(░).toBeLessThanOrEqual(░)█` |
| `tbn→` | `expect(░).toBeNull()█` |
| `tbt→` | `expect(░).toBeTruthy()█` |
| `tbu→` | `expect(░).toBeUndefined()█` |
| `tc→` | `expect(░list).toContain(░)█` |
| `tce→` | `expect(░list).toContainEqual(░)█` |
| `te→` | `expect(░).toEqual(░)█` |
| `thbc→` | `expect(░).toHaveBeenCalled()█` |
| `thbct→` | `expect(░).toHaveBeenCalledTimes(░)█` |
| `thbcw→` | `expect(░).toHaveBeenCalledWith(░)█` |
| `thblcw→` | `expect(░).toHaveBeenLastCalledWith(░)█` |
| `thl→` | `expect(░).toHaveLength(░)█` |
| `thp→` | `expect(░).toHaveProperty(░keyPath, ░value)█` |
| `thpd→` | `expect(░).toHaveProperty('disabled')█` |
| `thps→` | `expect(░).toHaveProperty('selected')█` |
| `tm→` | `expect(░).toMatch(░)█` |
| `tmis→` | `expect(░).toMatchInlineSnapshot(░)█` |
| `tmo→` | `expect(░).toMatchObject(░)█` |
| `tse→` | `expect(░).toStrictEqual(░)█` |
| `tt→` | expect(() => {
  █
}).toThrow(░)
|
| `tte→` | expect(() => {
  █
}).toThrowError(░)
|
| `ttemis→` | expect(() => {
  █
}).toThrowErrorMatchingInlineSnapshot()
|
| `ttems→` | expect(() => {
  █
}).toThrowErrorMatchingSnapshot()
|

### Skeleton

| Trigger | Result |
| --------: | ------------------------------------------------------------------------------------------- |
| `vsb→` | import { it, expect, describe } from 'vitest'

describe('░group', () => {
  it('░should', () => {
    const expected = '░expected'
    const actual = ░group(░argument)
    expect(actual).toBe(expected)█
  })
})
|

⇧ [Back to menu](#menu)

---

## Keyboard

Remember to complement the snippets with these keyboard shortcuts that can be used without needing to move the cursor to the start or to the end.

| Action | Win/Linux | macOS |
| ----------------- | -----------------: | ----------------: |
| Insert line above | `ctrl+shift+enter` | `cmd+shift+enter` |
| Insert line below | `ctrl+enter` | `cmd+enter` |

⇧ [Back to menu](#menu)

---

## Settings

The `editor.snippetSuggestions` setting in vscode `settings.json` will show snippets on top of the suggestion list.

```json
"editor.snippetSuggestions": "top"
```

⇧ [Back to menu](#menu)

---

## About

### Fork

- [vscode-jest-snippets](https://github.com/andys8/vscode-jest-snippets) - Jest snippets extension for VS Code

### Built With

- [VS Code](https://code.visualstudio.com/) - Code editing redefined.
- [Figma](https://www.figma.com/) - The collaborative interface design tool.
- [SWPM](https://www.npmjs.com/package/swpm) - One Package Manager to command them all.

### Contributing

Please read [CONTRIBUTING](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.

### Versioning

We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [Const & Props Snippets](https://github.com/deinsoftware/vscode-vitest-snippets/tags) on GitHub.

### Authors

- **Camilo Martinez** [[Equiman](http://github.com/equiman)]

See also the list of [contributors](https://github.com/deinsoftware/vscode-vitest-snippets/contributors) who participated in this project.

### Sponsors

If this project helps you, consider buying me a cup of coffee.

[![GitHub Sponsors](https://img.shields.io/badge/-GitHub%20Sponsors-gray?style=flat&labelColor=171515&logo=github&logoColor=white&link=https://github.com/sponsors/deinsoftware)](https://github.com/sponsors/deinsoftware)
[![paypal](https://img.shields.io/badge/-PayPal-gray?style=flat&labelColor=00457C&logo=paypal&logoColor=white&link=https://paypal.me/equiman/3)](https://paypal.me/equiman/3)

### License

This project is licensed under the MIT License - see the [LICENSE](LICENSE.md) file for details.

⇧ [Back to menu](#menu)