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

assertivedocs

v0.4.0

Published

Unit test plugin for JSDoc

Downloads

8

Readme

assertivedocs

JSDocs unit testing plugin

Run npm i assertivedocs to install.

Check out the docs for more information.

Getting Started

  1. Install assertive docs by running the below command in your terminal open in your project directory.
npm i assertivedocs
  1. Add assertivedocs/assertivedocs to plugins in your JSDoc config file. If you haven't made a config file for JSDoc, make one and make JSDoc use it when running.

  2. In your JSDoc config file, set opts.destination to "./docs". This will output your generated documentation to this folder, with the unit test results in a "unit-tests" folder. Note: As of 0.3.0 you can call your destination folder anything you would like.

  3. Finally, set template.default.layoutFile to "assertivedocs/layout.tmpl". This will ensure there is a link to your unit test results in your documentation's navigation menu.

Basic Assertion

The most basic form of unit test is an assertion: @assert - <list,of,arguments>=>expected_result.

/**
 * Greets a person by name.
 * @param {String} name - Name of the person to greet
 * @returns {String}
 * 
 * @assert - John=>Hello, John!
 */
function greet(name) {
  return `Hello, ${name}!`
}

module.exports = {
  greet,
}

The above code will output a table similar to the below when JSDoc is run.

| Test | Arguments | Expected | Results | |-----------|---------------|--------------|-------------| | | John | Hello, John! | true |

Naming tests

Including a single-word name - such as JohnTest - between @assert and the '-' will give the test a name. Changing the above example to @assert JohnTest - John=>Hello, John! will output a table similar to the one below.

| Test | Arguments | Expected | Results | |-----------|---------------|--------------|-------------| | JohnTest | John | Hello, John! | true |

Type Operators

By default, assertivedocs assumes all arguments and expected values are a string. The below table shows the different type operators that modify the arguments provided for the test. See the docs for how to handle arrays.

| Type | Operator | |----------|--------------| | String | :string | | Integer | :int | | Float | :number | | Boolean | :bool |

Null, NaN, and Undefined

assertivedocs provides operators for handling these keywords. These can be provided on their own instead of providing an argument or expected value. See the docs for examples.

| Type | Operator | |-----------|--------------| | null | :null | | NaN | :NaN | | undefined | :undefined |