Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

assert

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assert

commonjs assert - node.js api compatible

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14M
increased by18.09%
Maintainers
1
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 29 Dec 2013

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