$ cnpm install clean-assert
A simple, intuitive, extensible, and open-core TDD assertion library.
assert.assert and friends. No, really.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.
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.
See here. There's not a lot in terms of examples, but the API docs are self-explanatory enough usage is pretty obvious.
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:
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.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.assert.assert, assert.fail, or assert.failFormat once they're ready to test (in the first case) or fail (in the second).assert.notDeepOwnInclude(object, "key") is assert.deeplyHasOwn(object, "key").assert.oneOf(value, list) is assert.equalsAny(actual, [...expected])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".
Copyright (c) 2018 and later, Isiah Meadows me@isiahmeadows.com.
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.
Copyright 2013 - present © cnpmjs.org | Home |