npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

mock-sense

v0.2.0

Published

[![npm](https://img.shields.io/npm/v/mock-sense)](https://www.npmjs.com/package/mock-sense) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Readme

mock-sense

npm License: MIT

mock-sense is a CLI that scans unit test files for mock-related test smells:

  • over-mocking, based on a mock-to-assertion ratio
  • vacuous assertions that always pass
  • dead mocks that are configured but never used
  • unchecked mocks that are called without any follow-up assertion

Install

pnpm add -D mock-sense

Or run it locally in this repo:

pnpm install
pnpm build
node dist/index.js test/

Usage

mock-sense <path> [options]

Options:

  • --threshold <n>: Mock/assert ratio threshold. Default: 3.0
  • --json: Emit JSON instead of terminal output
  • --no-fail: Report only. Do not exit with status 1 when issues are found
  • --coverage: Show mock usage coverage for each test file
  • --suggest: Suggest missing assertions from mock call patterns
  • --ext <exts>: Comma-separated test file extensions. Default: .test.ts,.test.js,.spec.ts,.spec.js

What It Detects

Over-mocking

For each file, mock-sense counts lines matching mock patterns such as:

  • jest.mock(
  • vi.mock(
  • sinon.stub(
  • jest.fn(
  • vi.fn(
  • mock.
  • .mockReturnValue(
  • .mockResolvedValue(

It also counts assertion lines matching:

  • expect(
  • assert.
  • should.

If mocks / assertions is greater than the configured threshold, the file is flagged as suspicious.

Vacuous Assertions

mock-sense flags assertions that always pass, including:

  • assert.equal(true, true)
  • assert.ok(true)
  • assert.strictEqual(1, 1) and similar same-literal comparisons
  • expect(true).toBe(true)
  • assert.ok(undefined !== undefined)

Mock Coverage

mock-sense --coverage tracks locally defined mocks such as const sendEmail = jest.fn() and reports:

  • mocks that are never called
  • mocks that are called but never asserted on

Suggestions

mock-sense --suggest uses the same call analysis to recommend missing assertions such as:

  • expect(sendEmail).toHaveBeenCalledWith(...)
  • expect(result).toBeDefined() for unchecked mock return values

Examples

mock-sense test/
Analyzing 4 test files...

⚠  test/over-mocked.test.ts
   Mocks: 15 | Assertions: 2 | Ratio: 7.5 (suspicious, threshold: 3.0)

⚠  test/vacuous.test.ts
   Line 3: assert.equal(true, true)  ← vacuous assertion
   Line 4: assert.ok(undefined !== undefined)  ← vacuous assertion

✓  test/healthy.test.ts  (healthy)

Summary: 2 suspicious files, 2 vacuous assertions found.
Exit code: 1 (issues found)
mock-sense test --json --no-fail

Outputs structured JSON suitable for CI or custom reporting.

mock-sense test --coverage
mock-sense test --suggest