Socket
Socket
Sign inDemoInstall

assert

Package Overview
Dependencies
Maintainers
6
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assert

The node.js assert module, re-packaged for web browsers.


Version published
Weekly downloads
12M
decreased by-4.06%
Maintainers
6
Weekly downloads
 
Created

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

Keywords

FAQs

Package last updated on 07 Sep 2023

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc