
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.
A supplementary assertion library that runs on both NodeJS and browser.
# npm
npm install assertron
# yarn
yarn add assertron
# pnpm
pnpm install assertron
#rush
rush add -p assertron
assertron
provides a collection of assertion methods:
assertron.false(value)
: asserts the provided value is false.assertron.falsy(value)
: asserts the provided value is falsy.assertron.isInstanceof(value, ClassType)
: asserts value instanceof ClassType
.assertron.pathEqual(actual, expected)
: asserts the two paths are equal regardless of operating system differences.assertron.rejects(promise)
: asserts the promise rejects.assertron.repeat(fn, times)
: repeat the specified function n times and return the last result.assertron.resolves(promise)
: asserts the promise resolves.assertron.satisfies(actual, expected)
: checks if actual
meets the requirements specified by expected
.expected
can be a value, a RegExp
, or a predicate function.satisfier
internally to check for validity.satisfier
for more detail.import a from 'assertron' // assertron is also exported as default.
// these passes
a.satisfies({ a: 1, b: 2 }, { a: 1 })
a.satisfies({ a: 'foo', b: 'boo' }, { a: /foo/ })
a.satisfies({ a: 1, b, 2 }, { a: n => n === 1 })
// these fails
a.satisfies({ a: 1 }, { a: 2 })
a.satisfies({ a: 1 }, { a: 1, b: 2 })
a.satisfies({ a: 'foo' }, { a: /boo/ })
a.satisfies({ a: 1 }, { a: () => false })
assertron.throws(...)
: asserts the promise, function, or async function throws (or rejects) an error.import { assertron } from 'assertron'
await assertron.throws(Promise.reject(new Error('foo')))
assertron.throws(() => { throw new Error('foo') })
await assertron.throws(() => Promise.reject(new Error('foo')))
const e1 = await assertron.throws(Promise.reject(new SpecificError('foo')), SpecificError)
const e2 = assertron.throws(() => { throw new SpecificError('foo') }, SpecificError)
const e3 = await assertron.throws(() => Promise.reject(new SpecificError('foo')), SpecificError)
assertron.true(value)
: asserts the provided value is true.assertron.truthy(value)
: asserts the provided value is truthy.Assert the code is executed in the expected order.
order.once(step: number)
: asserts the step step
executed once.import { AssertOrder } from 'assertron'
const o = new AssertOrder()
function foo() {
o.once(1)
}
foo()
foo() // throws
import { AssertOrder } from 'assertron'
const o = new AssertOrder()
function foo() {
o.once(1)
}
function boo() {
o.once(2)
}
foo()
boo()
order.atLeastOnce(step: number)
: assert the step
executed at least once.import { AssertOrder } from 'assertron'
const o = new AssertOrder()
for (let i = 0; i < 10; i++)
o.atLeastOnce(1)
o.once(2)
order.exactly(step: number, times: number)
: asserts the step step
executed exactly n timesimport { AssertOrder } from 'assertron'
const o = new AssertOrder()
for (let i = 0; i < 4; i++)
o.exactly(1, 3) // throws at i === 3
order.any(steps: number[], handler?: (step: number) => void)
: asserts any of the steps steps
executed.import { AssertOrder } from 'assertron'
const o = new AssertOrder()
for (let i = 1; i <= 4; i++) {
if (i % 2)
o.any([1, 3])
else
o.any([2, 4])
}
There are other methods available. Use TypeScript to discover them!
yarn
# start making changes
git checkout -b <branch>
yarn watch
# after making change(s)
git commit -m "<commit message>"
git push
# create PR
There are a few useful commands you can use during development.
yarn test
yarn watch
yarn verify
11.5.2
FAQs
A supplementary assertion library
The npm package assertron receives a total of 323 weekly downloads. As such, assertron popularity was classified as not popular.
We found that assertron demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.