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 🙏

© 2026 – Pkg Stats / Ryan Hefner

expecting

v0.1.0

Published

Assertion library for Node and browsers

Downloads

12

Readme

Expecting.js

A minimalistic BDD assertion library. An actively maintained fork of expect.js.

In Node, npm install expecting, and then use it:

var expect = require('expecting')

expect('foo').to.equal('foo')
expect(5).to.be.a('number')

In the browser, grab dist/expecting.js, and then use it:

<script src="expecting.js"></script>
<script>
var expect = expecting

expect({ a: 'b' }).to.eql({ a: 'b' })
expect([]).to.be.an('array')
</script>

How to use with Mocha

Here's how to use this library with the Mocha testing library:

var expect = require('expecting')

describe('test suite', function () {
  it('does not break the laws of mathematics', function () {
    expect(1).to.equal(1)
  })
})

API

ok: assert whether a value is truthy.

expect(true).to.be.ok()
expect(1).to.be.ok()
expect({}).to.be.ok()

expect(false).to.not.be.ok()
expect(0).to.not.be.ok()

be (alias: equal): assert strict equality with ===. Also works for NaN.

expect(1).to.be(1)
expect('hi').to.be('hi')
expect(NaN).to.be(NaN)

expect('foo').not.to.be('bar')
expect({ hi: 5 }).not.to.be({ hi: 5 })
expect(1).not.to.be(true)
expect('1').to.not.be(1)

eql: assert loose equality that works with objects. Does a deep comparison if == fails.

expect(1).to.eql('1')
expect(undefined).to.eql(null)
expect({ a: 'b' }).to.eql({ a: 'b' })

expect(1).not.to.eql(2)

a (alias: an): assert that a property is of the correct type. Use string for primitives and constructors for more complex objects.

expect(5).to.be.a('number')
expect([]).to.be.an('array')
expect([]).to.be.an('object')
expect({}).to.be.an('object')

expect([]).to.be.an(Array)
expect(new Date()).to.be.a(Date)
expect(new Error()).to.be.an(Error)

match: assert that a string matches a regular expression.

expect('1.2.3').to.match(/[0-9]+\.[0-9]+\.[0-9]+/)

contain: assert that an array or string contains a value. Uses indexOf under the hood.

expect([1, 2]).to.contain(1)
expect('hello world').to.contain('world')

expect('hello world').not.to.contain('goodbye')

length: assert that an array (or array-like) has the right length.

expect([]).to.have.length(0)
expect([1, 2, 3]).to.have.length(3)
expect({ length: 5 }).to.have.length(5)

empty: if given an object, assert that it has no keys. If given an array or string, assert that it is empty. Throws an error if given other types.

expect('').to.be.empty()
expect([]).to.be.empty()
expect({}).to.be.empty()

expect({ my: 'object' }).to.not.be.empty()

expect(null).to.be.empty()  // throws an error

property: assert that a property is present, and optionally of a given value. Can also assert that the property is not inherited.

expect({ foo: 'boo' }).to.have.property('foo')
expect({ foo: 'boo' }).to.have.property('foo', 'boo')

function Klass() {
  this.ownProperty = 123
}
Klass.prototype.parentProperty = 456
var k = new Klass()

expect(k).to.have.property('ownProperty')
expect(k).to.have.own.property('ownProperty')
expect(k).to.have.property('parentProperty')
expect(k).not.to.have.own.property('parentProperty')

key (alias: keys): assert the presence of a key or keys. Supports the only modifier.

expect({ a: 'b' }).to.have.key('a')
expect({ a: 'b', c: 'd' }).to.only.have.keys('a', 'c')
expect({ a: 'b', c: 'd' }).to.only.have.keys(['a', 'c'])
expect({ a: 'b', c: 'd' }).to.not.only.have.key('a')

throw (aliases: throwException, throwError): assert that a function throws an error when called. Can optionally take a regular expression or a function to make more assertions about the exception.

function fn (message) {
  throw new Error(message || 'Oh no!')
}

expect(fn).to.throw()
expect(fn).to.throw(/Oh no/)

expect(fn).withArgs('Something bad happened.').to.throw(/Something bad/)

expect(fn).to.throw(function (err) {
  expect(err).to.be.an(Error)
})

expect(function () {}).not.to.throw()

between (alias: within): assert that a number is within a certain range.

expect(1).to.be.between(0, 10)

greaterThan (alias: above): assert that a value is greater than another (uses >).

expect(5).to.be.greaterThan(3)

lessThan (alias: below): assert that a value is less than another (uses <).

expect(0).to.be.lessThan(3)

greaterThanOrEqualTo (alias: atLeast): assert that a value is greater than or equal to another (uses >=).

expect(3).to.be.greaterThanOrEqualTo(0)
expect(5).to.be.greaterThanOrEqualTo(5)

lessThanOrEqualTo: assert that a value is less than or equal to another (uses <=).

expect(0).to.be.lessThanOrEqualTo(3)
expect(3).to.be.lessThanOrEqualTo(3)

fail: explicitly force failure.

expect().fail()                          // throws an error
expect().fail('Custom failure message')  // throws an error