
Security News
Google’s OSV Fix Just Added 500+ New Advisories — All Thanks to One Small Policy Change
A data handling bug in OSV.dev caused disputed CVEs to disappear from vulnerability feeds until a recent fix restored over 500 advisories.
assertions
Advanced tools
assertions is a powerful assertion toolkit.
there are many useful assertion functions,
including a few very useful higher order assertion functions.
also, every function has a _curry form and these can be joined together to create reusable specs.
##here I'll explain:
assert that bar
equals foo
var a = require('assertions')
a.equal(bar, foo)
create an assertion that anything equals foo
var equalFoo = a._equal(foo)
//apply it to some things...
equalFoo (bar)
equalFoo (baz)
equalFoo (zuk)
every function has a curry form with a leading "_",
it skips the first arg,
and returns an assertion function that you can pass the first arg to later!
okay, so why?
this starts to get super awesome when you have, example, the has
assertion:
//assert that bar has a property letters: 3, and a name, which is a string.
a.has(bar, {
letters: 3,
, name: function (actual) { a.isString(actual, 'make it a string!') }
})
has
is kinda like deepEqual
but only checks that the property matches if it's a primitive.
if the property is a function then has
assumes that it is an assertion function,
and applys the function to the corisponding property on the actual
object.
lets rewrite the above example using the curry form:
//assert that bar has a property letters: 3, and a name, which is a string.
var validTLA = a._has({
letters: 3,
name: a._isString('make it a string!')
}, 'must be a real Three Letter Acronym')
now we can check that every thing is a valid TLA, oh yeah, lets use the higher order assertion every
a.every([
{name: 'WTF', letters: 3},
{name: 'OMG', letters: 3},
{name: 'BBQ', letters: 3},
{name: 'TLA', letters: 3},
{name: 'DSL', letters: 3}
], validTLA)
we can now use validTLA
where ever we need to check that something is a TLA, not just in our tests.
one of the best things about assertions is that it creates very detailed error messages.
a.every([
{name: 'WTF', letters: 3},
{name: 'TLA', letters: 3},
{name: 'IMHO', letters: 4}
], validTLA)
will give you a message like this, showing each step of where it went wrong!
equal: 4 == 3
has: ({ name: "IMHO", letters: 4 }).letters must match { letters: 3, name: isString }).letters
every: every[2] (== { name: "IMHO", letters: 4 }) must pass has,
(2 out of 3 have passed)
at Object.equal (/home/dominic/source/dev/assertions/elementary.js:11:18)
at Object.leaf (/home/dominic/source/dev/assertions/higher.js:175:16)
...
that is the raw form of all assertions. this convention is borrowed from the nodejs assert
module.
some times expected
is not necessary, or is optional,
or may take multiple args. see assertion docs.
if the assertion takes optional args, the last arg is always message
if it is a string.
MIT
FAQs
loads of useful assert functions in one package
The npm package assertions receives a total of 648 weekly downloads. As such, assertions popularity was classified as not popular.
We found that assertions 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 data handling bug in OSV.dev caused disputed CVEs to disappear from vulnerability feeds until a recent fix restored over 500 advisories.
Research
/Security News
175 malicious npm packages (26k+ downloads) used unpkg CDN to host redirect scripts for a credential-phishing campaign targeting 135+ organizations worldwide.
Security News
Python 3.14 adds template strings, deferred annotations, and subinterpreters, plus free-threaded mode, an experimental JIT, and Sigstore verification.