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

clean-assert

v3.0.0

Published

A simple, intuitive TDD assertion library

Downloads

35

Readme

Build Status

Clean Assert

A simple, intuitive, extensible, and open-core TDD assertion library.

  • Very simple assertion-style syntax with intuitive names for each method.
  • About 100 built-in assertions, all fitting a few very simple patterns.
  • Custom assertions are simple functions that call assert.assert and friends. No, really.
  • Optimized assertions and matching algorithms keep assertions fast.
  • Very extensively tested - almost 4000 tests at the time of writing.
  • Tested in both Node LTS, modern browsers, and even PhantomJS 2!

So what isn't there to love?


Note: If you're concerned about the very minimal Git/version history, this library is actively maintained, and I personally use this with all new production projects I control; it's just very stable and what you might consider mostly done. Probably one of those 0.00001% of projects that are generally bug-free.

Installation

Install via npm or Yarn:

npm install --save-dev clean-assert
yarn add clean-assert

Or, if you just want to try it out in a browser, add one of these <script> elements to your <head>:

<!-- For the latest and greatest -->
<script src="https://unpkg.com/clean-assert/global.js"></script>

<!-- For version 3 -->
<script src="https://unpkg.com/clean-assert@3/global.js"></script>

<!-- If you prefer to use a local copy -->
<script src="./path/to/clean-assert/global.js"></script>

Note that if you use Rollup, this is exposed as a CommonJS module, not an ES module.

API

See here. There's not a lot in terms of examples, but the API docs are self-explanatory enough usage is pretty obvious.

Motivation

This was originally designed for Thallium when I first started working on that library, because I wanted something simple, yet intuitive, and something that didn't get in my way of testing crap. I apparently did a good enough job from the gate after decoupling it from that framework that I soon found it replacing Chai for me in all new code I wrote.

I also experienced a few other issues with other libraries:

  • An over-abundance of overly specific assertions like assert.isTrue(value) or assert.lengthOf(value, 1), which add literally nothing at best to the user experience. In this, there's no assert.isTrue(value), assert.lengthOf(value, 1) or other similarly niche methods. You just use assert.equal(value, true) or assert.hasIn(value, "length", 1), respectively.
  • An unnecessary reliance on identity for equality. If you read assert.equal({foo: 1}, {foo: 1}), you'd expect that to generally work if you're not thinking about strict equality semantics. In this, structural matching and value equality is the default, so assert.equal({foo: 1}, {foo: 1}) works exactly how you'd expect it would.
  • Plugins are extremely messy, complex, and suffer from name conflicts. In this, there's no such thing as a "plugin". Custom assertions just call assert.assert, assert.fail, or assert.failFormat once they're ready to test (in the first case) or fail (in the second).
  • Most assertion libraries use a language that doesn't read like English, but instead some horribly bastardized, broken English-like pseudo-language that's trying to be somehow declarative when it's not. In this, it's all based on proper English and using imperative language - how you say it is almost always how the method is named. For a couple concrete examples:

Contributing

Found a bug? Want a feature? Report it here! Want to contribute? Keep reading.

ESLint with my preset is used to lint, and Mocha is used to run the tests. Most of the source code is in index.js and lib/, and the tests are all in test/. There's various scripts and utilities in scripts/.

The implementation is generally composed of a combination of DSLs to avoid a large amount of repetition, since most of the assertions fit the mold of "type check, test something, then throw an error if it failed".

License

Copyright (c) 2018 and later, Isiah Meadows [email protected].

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.