Socket
Socket
Sign inDemoInstall

assert

Package Overview
Dependencies
28
Maintainers
41
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

assert

The assert module from Node.js, for the browser.


Version published
Maintainers
41
Weekly downloads
12,690,899
decreased by-6.47%

Weekly downloads

Package description

What is assert?

The assert npm package is a module that provides a set of assertion functions for verifying invariants. It is primarily used for writing tests to ensure that code behaves as expected. The module includes functions to test strict equality, deep equality, and various other conditions.

What are assert's main functionalities?

Strict Equality Assertion

This feature is used to test if two values are strictly equal using the === operator.

const assert = require('assert');
assert.strictEqual(1, 1, '1 is strictly equal to 1');

Deep Equality Assertion

This feature is used to test if two objects or arrays are equal by comparing their properties or elements.

const assert = require('assert');
assert.deepStrictEqual({ a: 1 }, { a: 1 }, 'Objects are deeply equal');

Assertion with a Predicate Function

This feature is used to test if a value passes a specified predicate function.

const assert = require('assert');
assert.ok(value => value > 10, 'Value is greater than 10');

Throws Assertion

This feature is used to test if a function throws an error as expected.

const assert = require('assert');
assert.throws(
  () => { throw new Error('Wrong value'); },
  Error,
  'Function should throw an Error'
);

Other packages similar to assert

Readme

Source

assert

The assert module from Node.js, for the browser.

Build Status npm npm

With browserify, simply require('assert') or use the assert global and you will get this module.

The goal is to provide an API that is as functionally identical to the Node.js assert API as possible. Read the official docs for API documentation.

Install

To use this module directly (without browserify), install it as a dependency:

npm install assert

Usage

The goal is to provide an API that is as functionally identical to the Node.js assert API as possible. Read the official docs for API documentation.

Inconsistencies with Node.js assert

Due to differences between browsers, some error properties such as message and stack will be inconsistent. However the assertion behaviour is as close as possible to Node.js and the same error code will always be used.

Contributing

To contribute, work on the source files. Then build and run the tests against the built files. Be careful to not introduce syntax that will be transpiled down to unsupported syntax. For example, for...of loops will be transpiled to use Symbol.iterator which is unavailable in IE.

Build scripts

npm run build

Builds the project into the build dir.

npm run dev

Watches source files for changes and rebuilds them into the build dir.

npm run test

Builds the source files into the build dir and then runs the tests against the built project.

npm run test:nobuild

Runs the tests against the built project without rebuilding first.

This is useful if you're debugging in the transpiled code and want to re-run the tests without overwriting any changes you may have made.

npm run test:source

Runs the tests against the unbuilt source files.

This will only work on modern Node.js versions.

npm run test:browsers

Run browser tests against the all targets in the cloud.

Requires airtap credentials to be configured on your machine.

npm run test:browsers:local

Run a local browser test server. No airtap configuration required.

When paired with npm run dev any changes you make to the source files will be automatically transpiled and served on the next request to the test server.

License

MIT © Joyent, Inc. and other Node contributors

Keywords

FAQs

Last updated on 12 May 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc