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

@dmail/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

@dmail/assert - npm Package Compare versions

Comparing version 3.13.0 to 3.14.0

114

package.json
{
"name": "@dmail/assert",
"version": "3.13.0",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/dmail/assert"
},
"publishConfig": {
"access": "public"
},
"module": "index.js",
"browser": "dist/global/main.js",
"main": "dist/commonjs/main.js",
"files": [
"/index.js",
"/src/",
"/dist/"
],
"dependencies": {
"@dmail/inspect": "1.0.0"
},
"devDependencies": {
"@jsenv/exploring-server": "1.5.0",
"@jsenv/testing": "1.13.0",
"@jsenv/node-launcher": "1.11.0",
"@jsenv/chromium-launcher": "1.9.0",
"@jsenv/core": "5.100.0",
"@jsenv/bundling": "1.10.0",
"@jsenv/codecov-upload": "1.6.0",
"@jsenv/eslint-config": "8.0.0",
"@jsenv/eslint-import-resolver": "4.7.0",
"@jsenv/prettier-config": "1.0.0",
"@jsenv/prettier-check-project": "2.9.0",
"@jsenv/node-module-import-map": "2.1.0",
"babel-eslint": "11.0.0-beta.0",
"prettier": "1.18.2",
"codecov": "2.3.0",
"eslint": "5.1.0",
"eslint-plugin-import": "2.6.0",
"rimraf": "2.6.2"
},
"scripts": {
"generate-import-map": "node ./script/generate-import-map/generate-import-map.js",
"start-exploring-server": "node ./script/start-exploring-server/start-exploring-server.js",
"start-continuous-testing": "node ./script/start-continuous-testing/start-continuous-testing.js",
"test": "node ./script/test/test.js",
"eslint-check": "eslint .",
"prettier-check": "node ./script/prettier-check/prettier-check.js",
"generate-coverage": "node ./script/generate-coverage/generate-coverage.js",
"upload-coverage": "node ./script/upload-coverage/upload-coverage.js",
"generate-global-bundle": "node ./script/generate-global-bundle/generate-global-bundle.js",
"generate-commonjs-bundle": "node ./script/generate-commonjs-bundle/generate-commonjs-bundle.js",
"dist": "npm run clean && npm run generate-global-bundle && npm run generate-commonjs-bundle",
"clean": "rimraf dist && rimraf coverage",
"reinstall": "npm run clean && rimraf node_modules && npm install",
"prepublishOnly": "npm run dist"
}
}
"name": "@dmail/assert",
"version": "3.14.0",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/dmail/assert"
},
"publishConfig": {
"access": "public"
},
"module": "index.js",
"browser": "dist/global/main.js",
"main": "dist/commonjs/main.js",
"files": [
"/dist/",
"/src/",
"/index.js"
],
"scripts": {
"start-exploring-server": "node ./script/start-exploring-server/start-exploring-server.js",
"start-continuous-testing": "node ./script/start-continuous-testing/start-continuous-testing.js",
"test": "node ./script/test/test.js",
"eslint-check": "eslint .",
"prettier-check": "node ./script/prettier-check/prettier-check.js",
"generate-coverage": "node ./script/generate-coverage/generate-coverage.js",
"upload-coverage": "node ./script/upload-coverage/upload-coverage.js",
"generate-global-bundle": "node ./script/generate-global-bundle/generate-global-bundle.js",
"generate-commonjs-bundle": "node ./script/generate-commonjs-bundle/generate-commonjs-bundle.js",
"generate-import-map": "node ./script/generate-import-map/generate-import-map.js",
"dist": "npm run clean && npm run generate-global-bundle && npm run generate-commonjs-bundle",
"clean": "rimraf dist && rimraf coverage",
"reinstall": "npm run clean && rimraf node_modules && npm install",
"prepublishOnly": "node ./script/transform-package/remove-postinstall.js && npm run dist",
"postpublish": "node ./script/transform-package/restore-postinstall.js"
},
"dependencies": {
"@dmail/inspect": "1.3.0"
},
"devDependencies": {
"@jsenv/exploring-server": "2.14.0",
"@jsenv/testing": "1.25.0",
"@jsenv/node-launcher": "1.16.0",
"@jsenv/chromium-launcher": "2.3.0",
"@jsenv/core": "5.135.0",
"@jsenv/bundling": "1.14.0",
"@jsenv/codecov-upload": "1.6.0",
"@jsenv/eslint-config": "9.8.0",
"@jsenv/prettier-config": "1.0.0",
"@jsenv/prettier-check-project": "3.2.0",
"@jsenv/node-module-import-map": "3.2.0",
"babel-eslint": "11.0.0-beta.0",
"prettier": "1.18.2",
"eslint": "6.2.1",
"rimraf": "3.0.0"
}
}

@@ -21,74 +21,227 @@ # assert

`assert` does nothing when `actual` and `expected` comparison is successfull.<br />
`assert` throw an error if `actual` and `expected` comparison is a failure.
`assert` throw an error if `actual` and `expected` comparison is failing.
## `assert` comparison
`actual` and `expected` can be different objects but they must deeply look alike in every aspects possible in JavaScript.
`actual` and `expected` can be different objects but they must deeply look alike in every aspects possible in JavaScript.<br />
### Success examples
To better understand if comparison will fail or not let's see some successfull comparison first and some failing comparisons afterwards.
### Successfull comparison examples
```js
const actual = new Error("message")
const expected = new Error("message")
import { assert } from "@dmail/assert"
// dates
{
const actual = new Date()
const expected = new Date()
assert({ actual, expected })
}
// errors
{
const actual = new Error("message")
const expected = new Error("message")
assert({ actual, expected })
}
// objects without prototype
{
const actual = Object.create(null)
const expected = Object.create(null)
assert({ actual, expected })
}
// regexps
{
const actual = /ok/
const expected = /ok/
assert({ actual, expected })
}
```
### Failing comparison examples
Various code examples where comparison between `actual` and `expected` is failing.<br />
Each code example is followed with the console output.
#### Failing on value
Code
```js
const actual = Object.create(null)
const expected = Object.create(null)
```
import { assert } from "@dmail/assert"
```js
const actual = new Date()
const expected = new Date()
const actual = 10
const expected = "10"
try {
assert({ actual, expected })
} catch (e) {
console.log(e.message)
}
```
```js
const actual = /ok/
const expected = /ok/
Console output
```console
AssertionError: unequal values.
--- found ---
10
--- expected ---
"10"
--- at ---
value
```
### Failure examples
#### Failing on prototype
- constructor failure
Code
```js
import { assert } from "@dmail/assert"
const actual = new TypeError()
const expected = new Error()
try {
assert({ actual, expected })
} catch (e) {
console.log(e.message)
}
```
- type failure
Console output
```js
const actual = 10
const expected = "10"
```txt
AssertionError: unequal prototypes.
--- prototype found ---
global.TypeError.prototype
--- prototype expected ---
global.Error.prototype
--- at ---
value[[Prototype]]
```
- primitive / object failure
#### Failing on property value
Code
```js
const actual = new String("foo")
const expected = "foo"
```
import { assert } from "@dmail/assert"
- property value failure
```js
const actual = { foo: true }
const expected = { foo: false }
try {
assert({ actual, expected })
} catch (e) {
console.log(e.message)
}
```
- property order failure
Console output
```txt
AssertionError: unequal values.
--- found ---
true
--- expected ---
false
--- at ---
value.foo
```
#### Failing on properties order
Code
```js
import { assert } from "@dmail/assert"
const actual = { foo: true, bar: true }
const expected = { bar: true, foo: true }
try {
assert({ actual, expected })
} catch (e) {
console.log(e.message)
}
```
- property description failure
Console output
```txt
AssertionError: unexpected properties order.
--- properties order found ---
"foo"
"bar"
--- properties order expected ---
"bar"
"foo"
--- at ---
value
```
#### Failing on property configurability
Code
```js
import { assert } from "@dmail/assert"
const actual = Object.defineProperty({}, "answer", { value: 42 })
const expected = { answer: 42 }
try {
assert({ actual, expected })
} catch (e) {
console.log(e.message)
}
```
Console output
```txt
AssertionError: unequal values.
--- found ---
"non-configurable"
--- expected ---
"configurable"
--- at ---
value.answer[[Configurable]]
```
## Why `assert` is so strict ?
As stated, `assert` is very strict on `actual` / `expected` comparison.<br />
In fact, you cannot be more strict except by using `===`.<br />
It is like that because unit test are testing your public interface.<br />
And any subtle change in that interface might break things using it.<br />
In scenarios where you don't fully control what you're testing you can provide a subset of what you want to test.<br />
Let's illustrate this with an example:
- you want to test a function called `whatever`
- you want to ensure it returns an object with `answer: 42`
- you don't want to ensure returned object contains only `answer: 42`
```js
import { assert } from "@dmail/assert"
import { whatever } from "./whatever.js"
const { answer } = whatever()
const actual = { answer }
const expected = { answer: 42 }
assert({ actual, expected })
```
## How to use

@@ -95,0 +248,0 @@

@@ -255,2 +255,3 @@ /* eslint-disable no-use-before-define */

const expectedPropertyNames = Object.getOwnPropertyNames(expected)
// eslint-disable-next-line no-unused-vars
for (const expectedPropertyName of expectedPropertyNames) {

@@ -265,2 +266,3 @@ comparePropertyDescriptor(comparison, expectedPropertyName, expected)

const expectedSymbols = Object.getOwnPropertySymbols(expected)
// eslint-disable-next-line no-unused-vars
for (const expectedSymbol of expectedSymbols) {

@@ -363,2 +365,3 @@ comparePropertyDescriptor(comparison, expectedSymbol, expected)

// first check actual entries match expected entries
// eslint-disable-next-line no-unused-vars
for (const actualEntry of actualEntries) {

@@ -427,2 +430,3 @@ const expectedEntry = expectedEntries[actualEntry.index]

let index = 0
// eslint-disable-next-line no-unused-vars
for (const actualEntry of actualEntries) {

@@ -429,0 +433,0 @@ const actualEntryMapping = entryMapping.find((mapping) => mapping.actualEntry === actualEntry)

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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