
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Node.js assertion library.
This library is created to assert the complex objects.
// Some test method returns this object
let actual = {
_id: '5945bf36ccb3fa0011e8533c',
name: 'John',
email: 'john@mail.com',
phones: [
{ type: 'mobile', number: '1234567' }
{ type: 'work', number: '567382' }
],
account: {
number: '11111',
registered: '2010-04-21'
},
createdAt: '2017-02-03'
}
// Ned to do the following assertions:
// _id is exists
// name and email match
// mobile phone is exists and it's a number
// account registered match
let expected = {
_id: '_mock_',
name: 'John',
email: 'john@mail.com',
phones: [
{ type: 'mobile', number: /^d{1,10}$/ }
],
account: {
registered: '2010-04-21'
}
}
nassert.assert(actual, expected)
# Add to project, should install it as dev dependency
$ npm i -D n-assert
const nassert = require('n-assert')
should('should find user by name', async () => {
let actual = await usersSrvc.getUserByName('John')
let expected = { /* some data */ }
nassert.assert(actual, expected)
})
assert(actual, expected, isEqual)
Asserts that actual
is equal to expected
.
actual
- actual object.expected
- expected object.isEqual
- performs a deep assertion between actual
and expected
to determine that they are indentical.assertResponse(res, expectedStatus, expectedBody)
Asserts that status and body in res
is equal to expectedStatus
and expectedBody
.
res
- http response.expectedStatus
- expected http response status.expectedBody
- expected http response body.assertFn
Asserts that stubbed function has been called or not, and if called, then with provided arguments. Warning! To use sinonMatch
function, sinon instance should be initialized via nassert.initSinon(sinon)
method.
inst
- object instance.fnName
- stubbed function name in the service.callCount
- count of function calles, one by default.nCall
- validates that method was called with provided args on that call, zero by default.expectedArgs
- expected single argument, should be __without-args__
if function is called without arguments.expectedMultipleArgs
- expected few arguments.sinonMatch(expected)
Calls sinon.match and compares actual
value with expected
using nassert.assert
. Returns true
if values identical, otherwise throws an error. Warning! To use sinonMatch
function, sinon instance should be initialized via nassert.initSinon(sinon)
method.
getObjectId()
Returns new mongodb ObjectId.
getObjectIdStr()
Returns new mongodb ObjectId in string format.
Alexander Mac
Licensed under the MIT license.
FAQs
Node assertion library
The npm package n-assert receives a total of 146 weekly downloads. As such, n-assert popularity was classified as not popular.
We found that n-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
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.