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

@fizzwiz/mockchain

v0.0.0-dev.1

Published

A mockable Promise library for easily testing asynchronous operations in isolation.

Readme

🃏 @fizzwiz/mockchain

A mockable Promise for testing asynchronous operations in distributed systems.

MockChain is a lightweight, fully mockable Promise subclass that allows you to test asynchronous communication among peers, servers, or browser clients. Each async operation can be wrapped in a MockChain, giving you full control over its resolution or rejection in tests.

🔗 Visit the blog: mockchain.blog.fizzwiz.cloud


✨ Features

  • Mockable Promises: Wrap any asynchronous operation and control its outcome.
  • Configurable auto-start: Pass autoStart = false to delay execution until .mock() or .fail() is manually invoked.
  • Delayed resolution/rejection: Use mockAfter and failAfter to simulate network latency.
  • Factory methods: Conveniently wrap fetch requests, WebSocket messages, or any event emitter.
  • Chainable: Preserves native Promise chaining while remaining mockable.
  • Root access: Use .root to access the first node in a chain.
  • Parent navigation: Access the previous node via .parent.

📦 Installation

npm install @fizzwiz/mockchain

Browser (via CDN)

<script src="https://cdn.jsdelivr.net/npm/@fizzwiz/mockchain/dist/mockchain.bundle.js"></script>
<script>
  const { MockChain } = window.mockchain;
</script>

The global mockchain object exposes all classes.


🚀 Quick Start

import { MockChain } from '@fizzwiz/mockchain';

// Implement a mockable async-like method
function doFetch(url, autoStart = true) {
  const chain = MockChain.from(fetch(url), autoStart)
    .then(res => res.json());
  return chain;
}

// Test the method in isolation
const chain = doFetch(undefined, false); // get a non-auto-start chain
chain.root.mock(new Response(JSON.stringify({ ok: true }))); // trigger the chain manually
const result = await chain; // the final resolved value
console.log(result); // -> { ok: true }

📘 API

Class: MockChain

Instance Methods

  • mock(value) — force resolve with value.
  • fail(error) — force reject with error.
  • mockAfter(ms, value) — resolve after a delay.
  • failAfter(ms, error) — reject after a delay.
  • Standard then, catch, and finally methods are overridden to preserve mockability.
  • .root — reference the top-level node of the chain.
  • .parent — reference the previous node in the chain.

Static Methods

  • resolve(value) — create a resolved MockChain.
  • reject(reason) — create a rejected MockChain.
  • from(valueOrPromise, autoStart = true, parent = null) — convert any Promise or value into a MockChain.
  • fromResponse(url, opts, autoStart = true) — wrap a fetch request.
  • fromMessage(ws, isMessage?, attach = false, autoStart = true) — wrap WebSocket messages.
  • fromEvent(emitter, eventName, isEvent?, attach = false, autoStart = true) — wrap any Node.js or browser event.

💡 Note: All static constructors support the autoStart flag:

  • When autoStart = true, the executor runs immediately (like a normal Promise).
  • When autoStart = false, execution is deferred until .mock() or .fail() is called.
  • fromResponse.mock() expects a Response object.
  • fromMessage, fromEvent.mock() expects the emitted event argument(s).

🥪 Example Use Cases

  • Testing distributed node communication and behavior in isolation — without a live network.
  • Simulating server or WebSocket responses in browser-based peers.
  • Mocking event-driven behaviors during development or CI runs.
  • Controlling intermediate steps in promise chains using .parent or .root.
  • Debugging async flows built from extemporaneous arrow functions rather than dedicated functions.

📝 Contributing

Contributions, ideas, and feedback are welcome! Please open an issue or pull request on GitHub.


📄 License

MIT © fizzwiz 🔗 mockchain.blog.fizzwiz.cloud