Vitest Snippets

January 20, 2026 ยท View on GitHub

Snippets info

Every space inside { } and ( ) means that this is pushed into next line :) $ represent each step after tab.


Vitest Test Structure

SnippetPurpose
ivessential imports for vitest
iveextra imports for vitest
d, desccreates a describe block
docreates a describe block that runs only
dscreates a describe block that will be skipped
i, itcreates an it block
iocreates an it block that runs only
iscreates an it block that will be skipped
itdcreates a test placeholder
iacreates an it block with async callback function
tcreates a test block
tocreates a test block that runs only
tscreates a test block that will be skipped
ttdcreates a test placeholder
tacreates an test block with async callback function

Vitest Lifecycle Hooks

SnippetPurpose
aaafterAll function is called once after all specs
aeafterEach function is called once after each spec
bebeforeEach function is called once before each spec
beabeforeEach with async callback function
babeforeAll function is called once before all specs
baabeforeAll with async function
aevcrafterEach mock clear and reset functions

Vitest Assertions - Matchers

SnippetPurpose
eexpect actual value
eaexpects the test to make the indicated number
ehaexpects the test to make at least one assertion
erjexpect promise rejects to
ersexpect promise resolves to
tbexpects the first argument to be equal
tbctexpects the first argument to be close to
tbdexpects the argument is defined
tbfexpects the argument is falsy
tbgtexpects the argument is greater than
tbgteexpects the argument is greater than or equal
tbidexpects the argument to be in the document
tbiexpects the argument is instance of
tbltexpects the argument is less than
tblteexpects the argument is less than or equal
tbnexpects the argument is null
tbtexpects the argument is truthy
tbuexpects the argument is undefined
tcexpects the list contains the item (===)
tceexpects the list contains the item (equals)
teexpects the first argument to be equal
thbcreturns true if the spy was called
thbctreturns true if the spy has been called given times
thbcwreturns true if the spy has been called with
thblcwreturns true if the spy has been last called with
thlexpects the object to have length
thpreturns true if the argument matches the property
thpdreturns true if the property disabled
thpsreturns true if the property selected
tmreturns true if the argument matches
tmismatches the most recent inline snapshot
tmoreturns true if the argument matches the object
tmsmatches the most recent snapshot
tseexpects the first argument to be strictly equal
ttexpects that the method will throw an error
tteexpects that the method will throw an error
ttemisthrow error matching the inline snapshot
ttemsthrow error matching the snapshot

Vitest Expect Any

SnippetPurpose
eavexpect any value type
easexpect any string type
eanexpect any number type
eabexpect any boolean type
eadexpect any date type
eafexpect any function type
eaaexpect any array type
eatexpect anything

Vitest Mocks & Spies

SnippetPurpose
vmcreates vi.mock()
vmrvcreates vi.mock() with resolved value
vfcreates vi.fn()
vfrvcreates vi.fn() with resolved value
cfcreates a mock variable for a vi.fn()
cfrvcreates a mock variable with resolved value
mrvassign a return value
mrvoassign a return value for only one call
vscreates vi.spyOn()
vsicreates vi.spyOn() with mock implementation
cscreates a spy variable for a vi.spyOn()
csicreates a spy variable with mock implementation