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

certain

v1.8.0

Published

An Assertion Library

Downloads

31

Readme

Certain

Certain is a simple assertion library.

Install:

$ npm install certain

Usage is pretty simple:

var certain = require('certain')

certain('a').equals('a')

certain(false).is.true() // this will throw an AssertionError

API

certain(actual)

main certain method is called with the actual value then there are chained methods which allow the actual value to be compared to the corresponding expected value.

If the assertion is not correct certain will throw an AssertionError (this means you can use your preferred test suite provided that it fails the test on error)

There are also a number of chained properties which are available to improve semantics for test readability these are:be, to, does, is

For each of the below assertion methods it is possible to invert the assertion type by using: not, doesnt for example: certain('a').does.not.equal('b')

#equals(expected, msg) & #not.equal(expected, msg)

Assert that actual value triple equals to the expected value

certain('a').equals('a')

certain('a').equals('b') // will throw AssertionError

certain('a').does.not.equal('b')

certain('a').does.not.equal('a') // will throw AssertionError

certain('a').does.notEqual('b')

certain('a').does.notEqual('a') // will throw AssertionError

#deepEquals(expected, msg) & #not.deepEqual(expected, msg)

Assert that the actual value deepEquals to expected (this checks the values of properties of a specified object rather than references)

certain({ a: 1 }).deepEquals({ a: 1 })

certain({ a: 1 }).deepEquals({ a: 2, b: 3 }) // will throw AssertionError

certain({ a: 1 }).does.not.deepEqual({ a: 2, b: 3 })

certain({ a: 1 }).does.not.deepEqual({ a: 1 }) // will throw AssertionError

certain({ a: 1 }).does.notDeepEqual({ a: 2, b: 3 })

certain({ a: 1 }).does.notEqls({ a: 1 }) // will throw AssertionError

#is.true( msg) & #is.not.true(msg)

Assert that actual value is or is not equal to true

certain(true).is.true('It is true!')

certain(false).is.true() // will throw AssertionError

certain(false).is.not.true()

certain(true).is.not.true() // will throw AssertionError

#is.false(msg) & #is.not.false(msg)

Assert that actual value is or is not equal to false

certain(false).is.false('It is false!')

certain(true).is.false() // will throw AssertionError

certain(true).is.not.false()

certain(false).is.not.false() // will throw AssertionError

#is.ok(msg) & #is.not.ok(msg)

Assert that actual value is truthy by checking: Boolean(expected)

certain(1).is.ok('It is OK!')

certain(0).is.ok() // will throw AssertionError

certain(false).is.not.ok()
certain(null).is.not.ok()
certain(undefined).is.not.ok()

certain(true).is.not.ok() // will throw AssertionError

#throws(msg) & #does.not.throw(msg)

This expects that the actual value passed is a function and will assert if this function throws an error when called

certain(function () {
  throw new Error()
}).throws()

certain(function () {
  return true
}).throws() // will throw AssertionError

certain(function () {
  return false
}).doesnt.throw()

certain(function () {
  throw new Error()
}).does.not.throw() // will throw AssertionError