Miss any of our Open RFC calls?Watch the recordings here! »

likewise

2.0.3 • Public • Published

about

Produces exceptions for failing assertions. Includes ready made assertions for truthiness and equality. Combines with tapeling in tapeless for TAP formatted output browser side.

setup

Download the latest stable version from the npm registry:

# Add to 'package.json' development dependencies 
npm install likewise --save-dev

usage

The named export reassert() is available for creating own assertions. For example,

import { reassert } from 'likewise'
 
// Basic truthiness checking
const truthy = v => !!v
const falsy = v => !v
 
// Wrap with `reassert()` to throw an `Error` with
// the 'expected' value and an 'operator' key on failure,
// the 2nd and 3rd arguments respectively
const ok = reassert(truthy, true, '!!')
const notOk = reassert(falsy, false, '!')
 
// Clean run
console.assert(ok(true), 'ok')
console.assert(notOk(0), 'not ok')

Additionally, if only checks for truthiness and equality are needed, ok() and equal() plus counterparts are attached to assert() already wrapped. For example,

import { assert } from 'likewise'
 
const { ok, notOk, equal, notEqual } = assert
 
// Clean run
console.assert(ok(true), 'ok')
console.assert(notOk(0), 'not ok')
 
// Internally rely on `Object.is()`
console.assert(equal(null, null), 'equal')
console.assert(notEqual(null, 0), 'not equal')

see also

Keywords

Install

npm i likewise

DownloadsWeekly Downloads

3

Version

2.0.3

License

ISC

Unpacked Size

7.59 kB

Total Files

7

Last publish

Collaborators

  • avatar