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

sweetest

v0.0.2

Published

Simple testing framework inspired by Jest

Readme

Sweetest

Simple testing framework inspired by Jest.

This is not a fully functional testing framework, it's just a simple example of how you can create your own testing framework. Why would you do that? Because it's fun, duh!

Usage

Well, it's very similar to Jest, you have the same describe, it and expect functions, just with (much) less features:

import { describe, it, expect } from 'sweetest';

describe('My test suite', () => {
  it('should pass', () => {
    expect(1 + 1).toBe(2);
  });

  it('should fail', () => {
    expect(1 + 1).toBe(3);
  });

  describe('Nested suite', () => {
    it('should pass', () => {
      expect(null).toBeNull();
    });
  });
});

The output will be something like this:

❌ My test suite
  ✅ should pass
  ❌ should fail
  ✅ Nested suite
    ✅ should pass

Matchers

Currently, there is a limited list of built in matchers:

  • toBe(value): Strict equality with value
  • toBeNull(): Strict equality with null

But, you can still create your own matchers, just like in Jest. A "matcher" is a function that receives the value to be tested along with the expected value, and throws an AssertionError if the value is not as expected:

import { addMatcher, AssertionError, type Matcher } from 'sweetest';

const toBeGreaterThan: Matcher = (value: number, expected: number) => {
  if (value <= expected) {
    throw new AssertionError(`Expected ${value} to be greater than ${expected}`);
  }
};

addMatcher('toBeGreaterThan', toBeGreaterThan);

If you're using TypeScript, you'll also need to extend the Matchers interface using "Module Augmentation":

declare module 'sweetest' {
  interface Matchers {
    toBeGreaterThan(value: number, expected: number): void;
  }
}

Hooks

Same as in Jest, you can use hooks to run code before and after each test, or before and after each suite:

import { describe, it, beforeEach, afterEach, beforeAll, afterAll } from 'sweetest';

describe('My test suite', () => {
  beforeAll(() => {
    console.log('Before all tests');
  });

  beforeEach(() => {
    console.log('Before each test');
  });

  afterEach(() => {
    console.log('After each test');
  });

  afterAll(() => {
    console.log('After all tests');
  });

  it('should pass', () => {
    expect(1 + 1).toBe(2);
  });
});

Mocks

You can also create mock functions using the sw.fn function, and assert if they were called using the toHaveBeenCalled, toHaveBeenCalledTimes and toHaveBeenCalledWith matchers:

import { describe, it, expect, sw } from 'sweetest';

describe('My test suite', () => {
  it('should call the mock function', () => {
    const mock = sw.fn((count: number) => {
      return count * 2;
    });

    mock(1);
    mock(2);
    mock(3);

    expect(mock).toHaveBeenCalled();
    expect(mock).toHaveBeenCalledTimes(3);
    expect(mock).toHaveBeenCalledWith(1);
  });
});