<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/the-node-js-built-in-test-runner-qw7ywroa9" -->

---
title: The Node.js built-in test runner | daily.dev
description: A practical walkthrough of Node.js's built-in test runner (node:test) and assertion library (node:assert), covering writing and running tests, strict...
canonical: https://daily.dev/posts/the-node-js-built-in-test-runner-qw7ywroa9
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: The Node.js built-in test runner | daily.dev
og:description: A practical walkthrough of Node.js's built-in test runner (node:test) and assertion library (node:assert), covering writing and running tests, strict...
og:url: https://daily.dev/posts/the-node-js-built-in-test-runner-qw7ywroa9
og:image: https://api.daily.dev/og/posts/QW7yWrOa9.png
og:image:alt: The Node.js built-in test runner
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.

# The Node.js built-in test runner

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

## Summary

A practical walkthrough of Node.js's built-in test runner (node:test) and assertion library (node:assert), covering writing and running tests, strict assertions, async tests, describe/it grouping, setup/teardown hooks, filtering and watch mode, mocking functions and methods, code coverage, reporters, and test isolation/concurrency. The guide argues that for many Node projects this built-in stack replaces the need for Jest, while noting that watch mode, module mocking, and coverage remain experimental in Node 24. It also gives guidance on when to reach for Vitest or Playwright instead.

## Full article

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

## Questions this post answers

### How do I run tests with the built-in Node.js test runner without installing Jest?

Node ships a test runner in node:test and assertions in node:assert/strict, which together form a complete test stack with no extra dependency. Write tests using the test() function from node:test, then run a single file with node --test price.test.js, or run all discovered test files with node --test. The process exits non-zero on failure, which works directly with CI.

_Developers weighing whether to add Jest or Vitest can compare tradeoffs on daily.dev before deciding._

### How do I mock a function or object method using Node's built-in test runner?

The test context in node:test provides a mock tracker accessed via t.mock. Use t.mock.fn(() => 'sent') to create a spy function, or t.mock.method(logger, 'info') to mock an existing object method, then inspect calls with properties like mock.callCount() and mock.calls[0].arguments. Tracked mocks are automatically restored when the test ends, and mocking works best at real boundaries like HTTP, time, or payments rather than internal functions.

_Anyone setting up mocking strategy in Node tests can find comparisons and patterns on daily.dev._

### Is code coverage or module mocking stable in Node.js 24's built-in test runner?

No, both remain experimental in Node 24. Code coverage requires the --experimental-test-coverage flag and reports line, branch, and function coverage, while module mocking also requires an experimental flag. Coverage only shows which code executed during tests, not whether the assertions are meaningful, so it should be used to spot gaps rather than as a substitute for thoughtful test design.

_Teams tracking which Node.js testing features are still experimental can follow updates on daily.dev._

## Similar posts on daily.dev

- [Comparing the best Node.js unit testing frameworks](https://daily.dev/posts/comparing-the-best-node-js-unit-testing-frameworks-ezow8yale) · LogRocket · 0 upvotes · 0 comments
- [Vitest: an introduction](https://daily.dev/posts/vitest-an-introduction-9rhl06sca) · Flavio Copes · 2 upvotes · 0 comments
- [How to Automate Your Tests in Express Using Vitest](https://daily.dev/posts/how-to-automate-your-tests-in-express-using-vitest-m3xroq8sb) · freeCodeCamp · 3 upvotes · 0 comments
- [Testing Node.js APIs with Jest: A Frontend Developer's Guide to Backend Testing](https://daily.dev/posts/testing-node-js-apis-with-jest-a-frontend-developer-s-guide-to-backend-testing-ykfrkag4k) · SitePoint · 0 upvotes · 0 comments

---

Tags: [#testing](https://daily.dev/tags/testing), [#nodejs](https://daily.dev/tags/nodejs)

[View this post on daily.dev](https://daily.dev/posts/the-node-js-built-in-test-runner-qw7ywroa9)

```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":"The Node.js built-in test runner","url":"https://daily.dev/posts/the-node-js-built-in-test-runner-qw7ywroa9","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/the-node-js-built-in-test-runner-qw7ywroa9"},"datePublished":"2026-08-29T09:21:47.131Z","dateModified":"2026-09-14T06:20:30.779Z","description":"A practical walkthrough of Node.js's built-in test runner (node:test) and assertion library (node:assert), covering writing and running tests, strict...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/c9d4cbc7683dc8c193a2e4f368620ef9?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/c9d4cbc7683dc8c193a2e4f368620ef9?_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/the-node-js-built-in-test-runner-qw7ywroa9","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"testing,nodejs","timeRequired":"PT7M"}
{"@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":"The Node.js built-in test runner"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/the-node-js-built-in-test-runner-qw7ywroa9#faq","mainEntity":[{"@type":"Question","name":"How do I run tests with the built-in Node.js test runner without installing Jest?","acceptedAnswer":{"@type":"Answer","text":"Node ships a test runner in node:test and assertions in node:assert/strict, which together form a complete test stack with no extra dependency. Write tests using the test() function from node:test, then run a single file with node --test price.test.js, or run all discovered test files with node --test. The process exits non-zero on failure, which works directly with CI. Developers weighing whether to add Jest or Vitest can compare tradeoffs on daily.dev before deciding."}},{"@type":"Question","name":"How do I mock a function or object method using Node's built-in test runner?","acceptedAnswer":{"@type":"Answer","text":"The test context in node:test provides a mock tracker accessed via t.mock. Use t.mock.fn(() =\u003e 'sent') to create a spy function, or t.mock.method(logger, 'info') to mock an existing object method, then inspect calls with properties like mock.callCount() and mock.calls[0].arguments. Tracked mocks are automatically restored when the test ends, and mocking works best at real boundaries like HTTP, time, or payments rather than internal functions. Anyone setting up mocking strategy in Node tests can find comparisons and patterns on daily.dev."}},{"@type":"Question","name":"Is code coverage or module mocking stable in Node.js 24's built-in test runner?","acceptedAnswer":{"@type":"Answer","text":"No, both remain experimental in Node 24. Code coverage requires the --experimental-test-coverage flag and reports line, branch, and function coverage, while module mocking also requires an experimental flag. Coverage only shows which code executed during tests, not whether the assertions are meaningful, so it should be used to spot gaps rather than as a substitute for thoughtful test design. Teams tracking which Node.js testing features are still experimental can follow updates on daily.dev."}}]}
```

