npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

n-assert

v7.0.0

Published

Node assertion library

Downloads

9,726

Readme

n-assert

Node.js assertion library.

Build Status Code Coverage npm version

Why

This library is created to assert the complex objects.

// Some test method returns this object
let actual = {
  _id: '5945bf36ccb3fa0011e8533c',
  name: 'John',
  email: '[email protected]',
  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: '[email protected]',
  phones: [
    { type: 'mobile', number: /^d{1,10}$/ }
  ],
  account: {
    registered: '2010-04-21'
  }
}

nassert.assert(actual, expected)

Commands

# Add to project, should install it as dev dependency
$ npm i -D n-assert

Usage

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)
})

API

  • 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.

Author

Alexander Mac

License

Licensed under the MIT license.