New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

assert-match

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assert-match

assert's matching features

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.4K
increased by5.1%
Maintainers
1
Weekly downloads
 
Created
Source

assert-match

assert-match is a set of additional assertions focused on matching. Unlike standard deep equality comparision assertions, which requires two arguments to have exactly the same sets of properties, assert-match' assertions requires one's arg properties to be superset of another arg properties.

Installation

    npm install assert-match

Assertions

assert (obj)

The function returned by imported module. Can be used to extend any passed obj object in it, for example, standatd assert module:

const assert = require('assert')
require('assert-match')(assert)

// ...

assert.match(actual, expected)

assert-match can also be used standalone:

const assert = require('assert-match')

// ...

assert.match(actual, expected)

Assertions

assert.match (actual, expected, message)

Tests whether the set of properties of the actual arg is superset of expected arg properties. Optional custom message is set on error when the assertion fails. Primitive values are compared with ==. Comparable to standard assert's deepEqual assertion but with another requirement on properties sets comparison.

assert.strictMatch (actual, expected, message)

Same as match, but primitives are compared with ===. Comparable to assert's deepStrictMatch.

assert.notMatch (actual, expected, message)

Same as match, but primitives are compared with !=. Comparable to assert's notDeepEqual.

assert.notStrictMatch (actual, expected, message)

Same as match, but primitives are compared with !==. Comparable to assert's notDeepStrictEqual.

Examples


import assert from 'assert'

describe('examples', function () {

    it('matches primitives', function () {
        assert.match(5, '5')
    })

    it('matches primitives strictly', function () {
        assert.strictMatch(5, 5)
    })

    it('matches objects', function () {
        assert.match({a: 1, b: 2, c: 3}, {a: 1})
    })

    it('throws when objects do not match', function () {
        assert.match({a: 1, b: 2, c: 3}, {a: 10})
    })

})

// RESULT

//   examples
//     ✓ matches primitives
//     ✓ matches primitives strictly
//     ✓ matches objects
//     1) throws when objects do not match


//   3 passing (82ms)
//   1 failing

//   1) examples throws when objects do not match:

//       AssertionError: { a: 1 } match { a: 10 }
//       + expected - actual

//        {
//       -  "a": 1
//       +  "a": 10
//        }

Keywords

FAQs

Package last updated on 26 Mar 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc