<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/vitest-an-introduction-9rhl06sca" -->

---
title: Vitest: an introduction | daily.dev
description: Vitest is a fast, Vite-powered test runner with a Jest-compatible API, native ESM and TypeScript support, watch mode, and built-in mocking. This introduction...
canonical: https://daily.dev/posts/vitest-an-introduction-9rhl06sca
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Vitest: an introduction | daily.dev
og:description: Vitest is a fast, Vite-powered test runner with a Jest-compatible API, native ESM and TypeScript support, watch mode, and built-in mocking. This introduction...
og:url: https://daily.dev/posts/vitest-an-introduction-9rhl06sca
og:image: https://api.daily.dev/og/posts/9rHL06scA.png
og:image:alt: Vitest: an introduction
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Vitest: an introduction

**[Flavio Copes](https://daily.dev/sources/flaviocopes)** · 4 min read · 2 upvotes · 0 comments

## Summary

Vitest is a fast, Vite-powered test runner with a Jest-compatible API, native ESM and TypeScript support, watch mode, and built-in mocking. This introduction covers installation, writing your first test, watch mode and the UI dashboard, common matchers (toBe, toEqual, toContain, toThrow), async tests, mocking with the vi namespace (vi.fn() and vi.mock()), and code coverage setup with @vitest/coverage-v8. TypeScript works out of the box with no extra configuration, and monorepos are supported via the projects config option.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://flaviocopes.com/vitest>

## Questions this post answers

### How do I write and run my first test with Vitest?

Install vitest as a dev dependency with npm, then create a test file using describe, it, and expect imported from vitest. Vitest automatically finds files matching *.test.js or *.spec.js patterns and runs them with npx vitest, defaulting to watch mode locally and a single run in CI environments.

_Developers picking up a new test runner can find setup walkthroughs like this on daily.dev._

### How do I mock a function or module in Vitest?

Use vi.fn() to create a trackable spy function, for example vi.fn((total) => total * 0.9), then assert calls with toHaveBeenCalledWith. To replace an entire module, call vi.mock('./api.js', () => ({...})) at the top of the test file, mirroring Jest's mocking patterns but under the vi namespace instead of jest.

_Anyone debugging mocking behavior in tests can browse practical examples like this on daily.dev._

### How do I measure test coverage with Vitest?

Install the @vitest/coverage-v8 package as a dev dependency, then run npx vitest run --coverage to print a coverage summary in the terminal. Reporters and coverage thresholds can be configured in vitest.config.ts for enforcing coverage gates in continuous integration pipelines.

_Teams setting coverage gates in CI often compare testing tool guides on daily.dev._

## Similar posts on daily.dev

- [Vitest vs Jest 2026: Performance Benchmarks & Migration Guide](https://daily.dev/posts/vitest-vs-jest-2026-performance-benchmarks-migration-guide-t3g4vuzdk) · SitePoint · 1 upvotes · 0 comments
- [Vitest 4.1: Test Tags, Native Node.js Execution and AI Agent Reporter](https://daily.dev/posts/vitest-4-1-test-tags-native-node-js-execution-and-ai-agent-reporter-leh7vktrz) · InfoQ · 1 upvotes · 0 comments
- [Setting Up Vitest for React and Next.js Applications](https://daily.dev/posts/setting-up-vitest-for-react-and-next-js-applications-0sldabkfz) · TypeScript.TV · 9 upvotes · 0 comments
- [The Node.js built-in test runner](https://daily.dev/posts/the-node-js-built-in-test-runner-qw7ywroa9) · Flavio Copes · 0 upvotes · 0 comments

---

Tags: [#javascript](https://daily.dev/tags/javascript), [#testing](https://daily.dev/tags/testing), [#typescript](https://daily.dev/tags/typescript), [#vite](https://daily.dev/tags/vite), [#vitest](https://daily.dev/tags/vitest)

[View this post on daily.dev](https://daily.dev/posts/vitest-an-introduction-9rhl06sca)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Vitest: an introduction","url":"https://daily.dev/posts/vitest-an-introduction-9rhl06sca","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/vitest-an-introduction-9rhl06sca"},"datePublished":"2026-08-04T07:25:48.460Z","dateModified":"2026-09-14T06:27:47.405Z","description":"Vitest is a fast, Vite-powered test runner with a Jest-compatible API, native ESM and TypeScript support, watch mode, and built-in mocking. This introduction...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/7219243bb6b6113ecc90bd933965a4ef?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/7219243bb6b6113ecc90bd933965a4ef?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Flavio Copes","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Flavio Copes","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/1f2dbd275797411bbd37bfdaaf0951a9","url":"https://daily.dev/sources/flaviocopes"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/vitest-an-introduction-9rhl06sca","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"javascript,testing,typescript,vite,vitest","timeRequired":"PT4M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Flavio Copes","item":"https://daily.dev/sources/flaviocopes"},{"@type":"ListItem","position":3,"name":"Vitest: an introduction"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/vitest-an-introduction-9rhl06sca#faq","mainEntity":[{"@type":"Question","name":"How do I write and run my first test with Vitest?","acceptedAnswer":{"@type":"Answer","text":"Install vitest as a dev dependency with npm, then create a test file using describe, it, and expect imported from vitest. Vitest automatically finds files matching *.test.js or *.spec.js patterns and runs them with npx vitest, defaulting to watch mode locally and a single run in CI environments. Developers picking up a new test runner can find setup walkthroughs like this on daily.dev."}},{"@type":"Question","name":"How do I mock a function or module in Vitest?","acceptedAnswer":{"@type":"Answer","text":"Use vi.fn() to create a trackable spy function, for example vi.fn((total) => total * 0.9), then assert calls with toHaveBeenCalledWith. To replace an entire module, call vi.mock('./api.js', () => ({...})) at the top of the test file, mirroring Jest's mocking patterns but under the vi namespace instead of jest. Anyone debugging mocking behavior in tests can browse practical examples like this on daily.dev."}},{"@type":"Question","name":"How do I measure test coverage with Vitest?","acceptedAnswer":{"@type":"Answer","text":"Install the @vitest/coverage-v8 package as a dev dependency, then run npx vitest run --coverage to print a coverage summary in the terminal. Reporters and coverage thresholds can be configured in vitest.config.ts for enforcing coverage gates in continuous integration pipelines. Teams setting coverage gates in CI often compare testing tool guides on daily.dev."}}]}
```

