Socket
Socket
Sign inDemoInstall

assert

Package Overview
Dependencies
Maintainers
3
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assert - npm Package Compare versions

Comparing version 1.4.1 to 1.5.0

CHANGELOG.md

16

assert.js
'use strict';
var objectAssign = require('object-assign');
// compare and isBuffer taken from https://github.com/feross/buffer/blob/680e9e5e488f22aac27599a57dc844a6315928dd/index.js

@@ -44,2 +46,4 @@ // original notice:

// based on node assert, original notice:
// NB: The URL to the CommonJS spec is kept just for tradition.
// node-assert has evolved a lot since then, both in API and behavior.

@@ -485,2 +489,14 @@ // http://wiki.commonjs.org/wiki/Unit_Testing/1.0

// Expose a strict only variant of assert
function strict(value, message) {
if (!value) fail(value, true, message, '==', strict);
}
assert.strict = objectAssign(strict, assert, {
equal: assert.strictEqual,
deepEqual: assert.deepStrictEqual,
notEqual: assert.notStrictEqual,
notDeepEqual: assert.notDeepStrictEqual
});
assert.strict.strict = assert.strict;
var objectKeys = Object.keys || function (obj) {

@@ -487,0 +503,0 @@ var keys = [];

30

package.json
{
"name": "assert",
"description": "commonjs assert - node.js api compatible",
"keywords": [
"assert"
],
"version": "1.4.1",
"homepage": "https://github.com/defunctzombie/commonjs-assert",
"repository": {
"type": "git",
"url": "git://github.com/defunctzombie/commonjs-assert.git"
},
"main": "./assert.js",
"description": "The node.js assert module, re-packaged for web browsers.",
"version": "1.5.0",
"dependencies": {
"object-assign": "^4.1.1",
"util": "0.10.3"

@@ -22,10 +14,20 @@ },

},
"homepage": "https://github.com/browserify/commonjs-assert",
"keywords": [
"assert",
"browser"
],
"license": "MIT",
"main": "./assert.js",
"repository": {
"type": "git",
"url": "git://github.com/browserify/commonjs-assert.git"
},
"scripts": {
"test-node": "mocha --ui qunit test.js",
"browser-local": "zuul --no-coverage --local 8000 -- test.js",
"test": "npm run test-node && npm run test-browser",
"test-browser": "zuul -- test.js",
"test": "npm run test-node && npm run test-browser",
"test-native": "TEST_NATIVE=true mocha --ui qunit test.js",
"browser-local": "zuul --no-coverage --local 8000 -- test.js"
"test-node": "mocha --ui qunit test.js"
}
}
# assert
[![Build Status](https://travis-ci.org/defunctzombie/commonjs-assert.svg?branch=master)](https://travis-ci.org/defunctzombie/commonjs-assert)
[![Build Status](https://travis-ci.org/browserify/commonjs-assert.svg?branch=master)](https://travis-ci.org/browserify/commonjs-assert)
This module is used for writing unit tests for your applications, you can access it with require('assert').
This module is used for writing unit tests for your applications, you can access it with `require('assert')`.
The API is derived from the [commonjs 1.0 unit testing](http://wiki.commonjs.org/wiki/Unit_Testing/1.0) spec and the [node.js assert module](http://nodejs.org/api/assert.html)
It aims to be fully compatibe with the [node.js assert module](http://nodejs.org/api/assert.html), same API and same behavior, just adding support for web browsers.
The API and code may contain traces of the [CommonJS Unit Testing 1.0 spec](http://wiki.commonjs.org/wiki/Unit_Testing/1.0) which they were based on, but both have evolved significantly since then.
A `strict` and a `legacy` mode exist, while it is recommended to only use `strict mode`.
## Strict mode
When using the `strict mode`, any `assert` function will use the equality used in the strict function mode. So `assert.deepEqual()` will, for example, work the same as `assert.deepStrictEqual()`.
It can be accessed using:
```js
const assert = require('assert').strict;
```
## Legacy mode
> Deprecated: Use strict mode instead.
When accessing `assert` directly instead of using the `strict` property, the
[Abstract Equality Comparison](https://tc39.github.io/ecma262/#sec-abstract-equality-comparison) will be used for any function without a
"strict" in its name (e.g. `assert.deepEqual()`).
It can be accessed using:
```js
const assert = require('assert');
```
It is recommended to use the `strict mode` instead as the Abstract Equality Comparison can often have surprising results. Especially
in case of `assert.deepEqual()` as the used comparison rules there are very lax.
E.g.
```js
// WARNING: This does not throw an AssertionError!
assert.deepEqual(/a/gi, new Date());
```
## assert.fail(actual, expected, message, operator)

@@ -24,2 +62,5 @@ Throws an exception that displays the values for actual and expected separated by the provided operator.

## assert.deepStrictEqual(actual, expected, [message])
Tests for deep equality, as determined by the strict equality operator ( === )
## assert.notDeepEqual(actual, expected, [message])

@@ -26,0 +67,0 @@ Tests for any deep inequality.

@@ -182,3 +182,3 @@ // Copyright Joyent, Inc. and other Node contributors.

test('assert - Testing the throwing', function () {
test('assert - testing the throwing', function () {
var aethrow = makeBlock(thrower, assert.AssertionError);

@@ -251,7 +251,7 @@ aethrow = makeBlock(thrower, assert.AssertionError);

test('assert - use a RegExp to validate error message', function () {
test('assert - use a RegExp to validate error message', function () {
assert.throws(makeBlock(thrower, TypeError), /test/);
});
test('assert - se a fn to validate error object', function () {
test('assert - use a fn to validate error object', function () {
assert.throws(makeBlock(thrower, TypeError), function(err) {

@@ -264,3 +264,3 @@ if ((err instanceof TypeError) && /test/.test(err)) {

test('assert - Make sure deepEqual doesn\'t loop forever on circular refs', function () {
test('assert - make sure deepEqual doesn\'t loop forever on circular refs', function () {
var b = {};

@@ -282,3 +282,3 @@ b.b = b;

test('assert - Ensure reflexivity of deepEqual with `arguments` objects', function() {
test('assert - ensure reflexivity of deepEqual with `arguments` objects', function() {
var args = (function() { return arguments; })();

@@ -349,2 +349,17 @@ assert.throws(makeBlock(assert.deepEqual, [], args), assert.AssertionError);

});
test('assert - strict mode', function () {
var assertStrict = assert.strict;
assertStrict.throws(makeBlock(assertStrict.equal, 1, true), assertStrict.AssertionError);
assertStrict.notEqual(0, false);
assertStrict.throws(makeBlock(assertStrict.deepEqual, 1, true), assertStrict.AssertionError);
assertStrict.notDeepEqual(0, false);
assertStrict.equal(assertStrict.strict, assertStrict.strict.strict);
assertStrict.equal(assertStrict.equal, assertStrict.strictEqual);
assertStrict.equal(assertStrict.deepEqual, assertStrict.deepStrictEqual);
assertStrict.equal(assertStrict.notEqual, assertStrict.notStrictEqual);
assertStrict.equal(assertStrict.notDeepEqual, assertStrict.notDeepStrictEqual);
assertStrict.equal(Object.keys(assertStrict).length, Object.keys(assert).length);
});
}

Sorry, the diff of this file is not supported yet

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