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 🙏

© 2024 – Pkg Stats / Ryan Hefner

unit-test-sentinel

v1.0.1

Published

Provides a sentinel object that can contain and return arbitrary unique properties for unit tests.

Downloads

4,142

Readme

Unit test sentinel

Provides unique objects for unit tests in JavaScript. Inspired by the sentinel object in Python.

It's useful for creating a value that is passed into a function call, but you don't want to keep track of this value in a local variable. Instead, you can ask the sentinel to give you a unique named property that will persist through your test.

Installation

npm install --save-dev unit-test-sentinel

Usage

Import the module sentinel and then create a sentinel object for each test. This example uses Mocha and calls the sentinel object ф (which is U+0444).

import sentinel from 'unit-test-sentinel'

// We'll test this function.
const logAndReturn = (input) => {
  console.log(input);
  return input;
};

describe('logAndReturn', () => {
  let ф;

  beforeEach(() => {
    // Create a sentinel object, which can contain arbirary properties.
    ф = sentinel.create();
  })

  it('returns its input', () => {
    // Pass in a custom input, as a named property.
    const result = logAndReturn(ф.customInput);

    // Expect that the output is the exact same object that was passed in.
    expect(result).to.equal(ф.customInput);
  })
});

This example require()s the sentinel module, uses assert for testing, and calls the sentinel object s. It also uses the random method, calling its object r.

const sentinel = require('unit-test-sentinel');
const s = sentinel.create();
const r = sentinel.random();

const first = s.hello; // => ¦ф.hello¦
const second = s.hello; // => ¦ф.hello¦
assert(first === second); // ✓

const r1 = s.randomized; // e.g. => randomized-WfQ8S;0{|+)t
const r2 = s.randomized; // => randomized-WfQ8S;0{|+)t
assert(r1 === r2); // ✓