Vitest Snippets


The quick and easy way to create and use Vitest with VS Code.
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
:
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
⇧ Back to menu
Supported Languages
Language |
Extension |
JavaScript |
.js |
TypeScript |
.ts |
JavaScript React |
.jsx |
TypeScript React |
.tsx |
Vue |
.vue |
⇧ Back to menu
Snippets
Below is a list of all available snippets and the triggers of each one. The → means the TAB
key and █
the final cursor position.
Import
Trigger |
Result |
iv→ |
import { it, expect, describe } from 'vitest'█ |
Setup
Trigger |
Result |
ae→ |
afterEach(() => { █ }) |
aa→ |
afterAll(() => { █ }) |
be→ |
beforeEach(() => { █ }) |
bea→ |
beforeEach(async () => { █ }) |
ba→ |
beforeAll(() => { █ }) |
baa→ |
beforeAll(async () => { █ }) |
Describe
Trigger |
Result |
d→ |
describe('group', () => { █ }) |
do→ |
describe.only('group', () => { █ }) |
ds→ |
describe.skip('group', () => { █ }) |
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(() => █) |
It
Trigger |
Result |
i→ |
it('should', () => { █ }) |
io→ |
it.only('should', () => { █ }) |
is→ |
it.skip('should', () => { █ }) |
it→ |
it.todo('should')█ |
ia→ |
it('should', async () => { █ }) |
Test
Trigger |
Result |
t→ |
test('should', () => { █ }) |
to→ |
test.only('should', () => { █ }) |
ts→ |
test.skip('should', () => { █ }) |
tt→ |
test.todo('should')█ |
ta→ |
test('should', async () => { █ }) |
Expect
Trigger |
Result |
e→ |
expect(█) |
ea→ |
expect.assertions(█) |
eha→ |
expect.hasAssertions()█ |
erj→ |
expect( ).rejects█ |
ers→ |
expect( ).resolves |
Assertion
Trigger |
Result |
tb→ |
expect( ).toBe( )█ |
tbct→ |
expect( ).toBeCloseTo( )█ |
tbd→ |
expect( ).toBeDefined( )█ |
tbf→ |
expect( ).toBeFalsy( )█ |
tbgt→ |
expect( ).toBeGreaterThan( )█ |
tbgte→ |
expect( ).toBeGreaterThanOrEqual( )█ |
tbi→ |
expect( ).toBeInstanceOf( )█ |
tblt→ |
expect( ).toBeLessThan( )█ |
tblte→ |
expect( ).toBeLessThanOrEqual( )█ |
tbn→ |
expect( ).toBeNull( )█ |
tbt→ |
expect( ).toBeTruthy( )█ |
tbu→ |
expect( ).toBeUndefined( )█ |
tc→ |
expect( ).toContain( )█ |
tce→ |
expect( ).toContainEqual( )█ |
te→ |
expect( ).toEqual( )█ |
thbc→ |
expect( ).toHaveBeenCalled( )█ |
thbct→ |
expect( ).toHaveBeenCalledTimes( )█ |
thbcw→ |
expect( ).toHaveBeenCalledWith( )█ |
thblcw→ |
expect( ).toHaveBeenLastCalledWith( )█ |
thl→ |
expect( ).toHaveLength( )█ |
thp→ |
expect( ).toHaveProperty(keyPath, value)█ |
tm→ |
expect( ).toMatch( )█ |
tmis→ |
expect( ).toMatchInlineSnapshot( )█ |
tmo→ |
expect( ).toMatchObject( )█ |
tse→ |
expect( ).toStrictEqual( )█ |
tt→ |
expect(() => { █ }).toThrow( ) |
tte→ |
expect(() => { █ }).toThrowError( ) |
ttemis→ |
expect(() => { █ }).toThrowErrorMatchingInlineSnapshot( ) |
ttems→ |
expect(() => { █ }).toThrowErrorMatchingSnapshot( ) |
⇧ Back to menu
Settings
The editor.snippetSuggestions
setting in vscode settings.json
will show snippets on top of the suggestion list.
"editor.snippetSuggestions": "top"
⇧ Back to menu
About
Fork
Built With
- VS Code - Code editing redefined.
- Figma - The collaborative interface design tool.
Contributing
Please read CONTRIBUTING for details on our code of conduct, and the process for submitting pull requests to us.
Versioning
We use SemVer for versioning. For the versions available, see the Const & Props Snippets on GitHub.
Authors
See also the list of contributors who participated in this project.
If this project helps you, consider buying me a cup of coffee.

License
This project is licensed under the MIT License - see the LICENSE file for details.
⇧ Back to menu