gitwtfhub

wtf is test-extras?

sindresorhus/test-extras — explained in plain English

Analysis updated 2026-05-18

17JavaScriptAudience · developerComplexity · 1/5Setup · easy

TL;DR

A lightweight assertion library that adds richer test checks, like error-returning throws and shape-based matchers, on top of Node's basic assert module.

Mindmap

Mindmap is still cooking. Refresh in a few.

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Why would anyone build with this?

REASON 1

Write tests with a throws assertion that returns the caught error for further checks.

REASON 2

Use asymmetric matchers to check that an object or array has a certain shape without an exact match.

REASON 3

Add missing checks like isEmpty, inRange, or sameMembers to a plain node:test or Vitest suite.

REASON 4

Replace ad-hoc custom assertion helpers with a single small dependency.

What's in the stack?

JavaScriptNode.jsTypeScript

How it stacks up

sindresorhus/test-extrasajaxfnc-yt/d.w.i.falanhuang168/ai-project-workflow
Stars171717
LanguageJavaScriptJavaScriptJavaScript
Setup difficultyeasymoderateeasy
Complexity1/52/53/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you spin it up?

Difficulty · easy Time to first run · 5min

Install with npm as a dev dependency and import the specific functions you need.

Wtf does this do

test-extras is a small helper library for writing tests in JavaScript or TypeScript. Node's own built in assert module is deliberately basic, and this package fills in the gaps with the kind of assertions people are used to from testing frameworks like AVA and Jest, such as a throws check that actually hands you back the error it caught so you can inspect it further. Every function in the package is a plain standalone function that raises an AssertionError when a check fails, so it is not tied to any particular test runner. It works equally well inside node:test, Vitest, or even a plain script with no test runner at all, and it does not modify or depend on any of them. You install it as a development dependency with npm, then import only the specific assertions or matchers you need. The library covers a wide range of situations: catching thrown errors and rejected promises while returning the error itself, checking numeric closeness for floating point comparisons, checking whether a collection includes or excludes a value, checking a value is one of several allowed options, comparing arrays regardless of order, checking types with instanceOf, and checking whether something is empty. It also provides asymmetric matchers, a way of checking that a value matches a shape or type rather than an exact value. These matchers, such as any type checks, objectContaining for partial object matching, arrayContaining for partial array matching, and stringMatching for pattern based string checks, are used inside a matches function and can be nested inside each other to build flexible checks on objects and arrays. Overall this is a lightweight testing utility aimed at developers who want richer, more expressive assertions than Node's built in assert module offers, without committing to a full alternate testing framework.

Yoink these prompts

Prompt 1
I'm using node:test and want an assertion like Jest's expect.objectContaining, how do I use test-extras' matches and objectContaining functions?
Prompt 2
Show me how to use throwsAsync from test-extras to catch a rejected promise and assert on the error it returns.
Prompt 3
I need to check that two arrays have the same elements regardless of order, how does sameMembers in test-extras work?
Prompt 4
Explain the difference between test-extras' arrayContaining and sameMembers functions.

Frequently asked questions

wtf is test-extras?

A lightweight assertion library that adds richer test checks, like error-returning throws and shape-based matchers, on top of Node's basic assert module.

What language is test-extras written in?

Mainly JavaScript. The stack also includes JavaScript, Node.js, TypeScript.

How hard is test-extras to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is test-extras for?

Mainly developer.

View the repo → Decode another repo

This repo across BitVibe Labs

Don't trust strangers blindly. Verify against the repo.