code
    Overview
    Documentation
    Tutorials
    Chat
    Insights
    Code
    Dependencies
    Contributors
    Jobs

code

assertion library

5.2.4  •  Updated 1 years ago  •  by hapijs  •  BSD 3-Clause "New" or "Revised" License

BDD assertion library.

Current Version Build Status

Lead Maintainer - Colin Ihrig

Example

const Code = require('code');
const expect = Code.expect;

expect(true).to.be.a.boolean().and.to.not.equal(false);
expect('this string').to.only.include(['this', 'string']);

Acknowledgments

code was created as a direct rewrite of the powerful chai assertions library. This virtual fork was created for a few reasons. First, chai mixed usage of methods and properties creates a problematic environment in which it is too easy to forget a method () and result in an assertion that is never executed (and therefor passes incorrectly). This observation was noted by the must author.

The second reason is that similar to lab, our test runner, we wanted an assertion library that is small, simple, and intuitive - without plugins, extensions, or the overhead of having to support testing in the browser. code provides much of the same functionality in about 300 lines of code that are trivial to read in a few minutes.

And last, we wanted to experiment with some new features that allow deeper integration between the test runner and assertions library. The first of which are two methods exported (and used by lab) for getting the total assertions count (which is a measure of the tests comprehensiveness), and by verifying that every assertion created (e.g. every expect() call) is also executed. This will alert when a statement like expect(5).to.be.a.string is not allowed to remain unnoticed (and fail to throw due to the missing ()).

Like lab, the goal is to keep this module small and simple. If you need extensibility or other functionality, we recommend looking at the many other excellent assertions libraries available.

API

See the API Reference.

Popularity

Maintenance

Development

Last ver 1 year ago
Created 8 years ago
Last commit 6 months ago
10 days between commits

Technology

Node version: 11.2.0
19K unpacked

Compliance

BSD 3-Clause "New" or "Revised" License
OSI Approved
0 vulnerabilities

Contributors

31 contributors
cjihrig
Maintainer, 70 commits, 35 merges, 17 PRs
Eran Hammer
Maintainer, 62 commits, 8 merges, 7 PRs
Works at Sideway Inc.
Wyatt Preul
Maintainer, 4 commits, 4 merges
Works at Joyent
Adam Bretz
5 commits, 2 merges, 1 PRs
Works at webflow
Gergo Erdosi
7 commits
Nicolas Morel
Maintainer, 4 commits, 2 merges, 3 PRs

Tags

test
expect
assertion
Openbase helps developers choose among and use millions of open-source packages, so they can build amazing products faster.
FacebookTwitterLinkedIn
© 2020 Devstore, Inc.