
Security News
High Salaries No Longer Enough to Attract Top Cybersecurity Talent
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
@dmail/assert
Advanced tools
[](https://www.npmjs.com/package/@dmail/assert) [](http://travis-ci.com/dmail/assert) [
assert
does nothing when actual
and expected
comparison is successfull.
assert
throw an error if actual
and expected
comparison is failing.
assert
comparisonactual
and expected
can be different objects but they must deeply look alike in every aspects possible in JavaScript.
To better understand if comparison will fail or not let's see some successfull comparison first and some failing comparisons afterwards.
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 })
}
Various code examples where comparison between actual
and expected
is failing.
Each code example is followed with the console output.
Code
import { assert } from "@dmail/assert"
const actual = 10
const expected = "10"
try {
assert({ actual, expected })
} catch (e) {
console.log(e.message)
}
Console output
AssertionError: unequal values.
--- found ---
10
--- expected ---
"10"
--- at ---
value
Code
import { assert } from "@dmail/assert"
const actual = new TypeError()
const expected = new Error()
try {
assert({ actual, expected })
} catch (e) {
console.log(e.message)
}
Console output
AssertionError: unequal prototypes.
--- prototype found ---
global.TypeError.prototype
--- prototype expected ---
global.Error.prototype
--- at ---
value[[Prototype]]
Code
import { assert } from "@dmail/assert"
const actual = { foo: true }
const expected = { foo: false }
try {
assert({ actual, expected })
} catch (e) {
console.log(e.message)
}
Console output
AssertionError: unequal values.
--- found ---
true
--- expected ---
false
--- at ---
value.foo
Code
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)
}
Console output
AssertionError: unexpected properties order.
--- properties order found ---
"foo"
"bar"
--- properties order expected ---
"bar"
"foo"
--- at ---
value
Code
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
AssertionError: unequal values.
--- found ---
"non-configurable"
--- expected ---
"configurable"
--- at ---
value.answer[[Configurable]]
assert
is so strict ?As stated, assert
is very strict on actual
/ expected
comparison.
In fact, you cannot be more strict except by using ===
.
It is like that because unit test are testing your public interface.
And any subtle change in that interface might break things using it.
In scenarios where you don't fully control what you're testing you can provide a subset of what you want to test.
Let's illustrate this with an example:
whatever
answer: 42
answer: 42
import { assert } from "@dmail/assert"
import { whatever } from "./whatever.js"
const { answer } = whatever()
const actual = { answer }
const expected = { answer: 42 }
assert({ actual, expected })
npm install --save-dev @dmail/assert
You can refer on browser example and node example below to go further.
<script src="https://unpkg.com/@dmail/assert@latest/dist/global/main.js"></script>
<script>
const { assert } = window.__dmail_assert__
assert({
actual: { foo: false },
expected: { foo: true },
})
</script>
Screnshot below is a part of console content after executing above code inside chrome.
const { assert } = require("@dmail/assert")
assert({
actual: { foo: false },
expected: { foo: true },
})
Screnshot below is a part of terminal output after executing above code inside node.js.
— see https://dmail.github.io/assert/browser-interactive-example/browser-interactive-example.html.
— see https://dmail.github.io/assert/node-interactive-example/node-interactive-example.html
FAQs
[](https://www.npmjs.com/package/@dmail/assert) [](http://travis-ci.com/dmail/assert) [![codecov](https://codecov.io/gh/dmail/asser
The npm package @dmail/assert receives a total of 18 weekly downloads. As such, @dmail/assert popularity was classified as not popular.
We found that @dmail/assert demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
Product
Socket, the leader in open source security, is now available on Google Cloud Marketplace for simplified procurement and enhanced protection against supply chain attacks.
Security News
Corepack will be phased out from future Node.js releases following a TSC vote.