# assertivedocs

> Unit test plugin for JSDoc

Latest version **0.4.0** (published 2022-06-05) · ISC license · 0 weekly downloads

## Install

```sh
npm install assertivedocs
pnpm add assertivedocs
yarn add assertivedocs
bun add assertivedocs
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2022-06-05 |
| First published | 2022-06-01 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 13 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | snailcreature |
| Maintainers | snailcreature |
| Keywords | testing, unit-testing |

## Links

- npm: https://www.npmjs.com/package/assertivedocs
- Repository: https://github.com/snailcreature/assertivedocs
- Homepage: https://assertivedocs.snail.codes
- Issues: https://github.com/snailcreature/assertivedocs/issues
- npm.io page: https://npm.io/package/assertivedocs

## Dependencies (1)

- [assertivedocs](https://npm.io/package/assertivedocs.md) file:../assertivedocs

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 0.4.0 (latest) — 2022-06-05
- 0.3.1 — 2022-06-04
- 0.3.0 — 2022-06-04
- 0.2.0 — 2022-06-01
- 0.1.0 — 2022-06-01

## README

# assertivedocs

JSDocs unit testing plugin

Run `npm i assertivedocs` to install.

[Check out the docs](https://assertivedocs.snail.codes) 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
```

2. Add `assertivedocs/assertivedocs` to `plugins` in your JSDoc config file. If you haven't made a 
config file for JSDoc, [make one](https://jsdoc.app/about-configuring-jsdoc.html) and [make JSDoc use it when running](https://jsdoc.app/about-commandline.html).

3. 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.`

4. 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`.

```javascript
/**
 * 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.](https://assertivedocs.snail.codes/tutorial-typeoperators.html)

| **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](https://assertivedocs.snail.codes/tutorial-nullnanundefined.html).

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

---
_Source: https://npm.io/package/assertivedocs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
