Socket
Socket
Sign inDemoInstall

power-assert-match

Package Overview
Dependencies
193
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    power-assert-match

power + assert-match >:3


Version published
Weekly downloads
7
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Build Status

power-assert-match

assert-match empowered.

Short example

import assert from 'power-assert-match'
const { arrayOf, type } = assert.matchers

const nums = [ 1, 2, 'x' ]
const expectedType = 'number'

assert.deepEqual({ nums: nums }, { nums: arrayOf(type(expectedType)) })

//      AssertionError:   # test/power-assert-match.spec.js:30
//
//  assert.deepEqual({ nums: nums }, { nums: arrayOf(type(expectedType)) })
//                   |       |       |       |       |    |
//                   |       |       |       |       |    "number"
//                   |       |       |       |       TypeMatcher{expected:"number"}
//                   |       |       |       ArrayOfMatcher{expected:#TypeMatcher#}
//                   |       |       Object{nums:#ArrayOfMatcher#}
//                   |       [1,2,"x"]
//                   Object{nums:#Array#}
//
//      + expected - actual
//
//       {
//         "nums": [
//           1
//           2
//      -    "x"
//      +    {
//      +      "[typeof]": "number"
//      +    }
//         ]
//       }

Installation

    npm install power-assert-match

Usage

Usage of power-assert-match is quite similar to that of power-assert:

  1. require power-assert-match
const assert = require('power-assert-match')
  1. use it
const { loose } = assert.matchers

const actual = { a: 1, b: 2 }
const expected = { a: 10 }

assert.deepEqual(actual, loose(expected))
  1. to get descriptive messages like one in the example above you need to transform your code using one of power-assert instrumentors:

Note, that unlike for power-assert, where require('assert') calls are substituted by the instrumentors with require('power-assert'), to use power-assert-match you need to require it directly.

After applying transform you get the following output:

assert.deepEqual(actual, loose(expected))
                 |       |     |
                 |       |     Object{a:10}
                 |       LooseMatcher{expected:#Object#}
                 Object{a:1,b:2}

More output examples

assert.deepEqual(val, not(val))
                 |    |   |
                 |    |   5
                 5    NotMatcher{expected:5}


assert.deepEqual(number, regex(numRegex))
                 |       |     |
                 |       |     /^\d+$/
                 "555f"  RegexMatcher{expected:/^\d+$/}


assert.deepEqual({ val: a }, { val: every([gt(b), lt(c)]) })
                 |      |    |      |     ||  |   |  |
                 |      |    |      |     ||  |   |  10
                 |      |    |      |     ||  5   LtMatcher{expected:10}
                 |      |    |      |     |GtMatcher{expected:5}
                 |      |    |      |     [#GtMatcher#,#LtMatcher#]
                 |      |    |      EveryMatcher{expected:#Array#}
                 |      15   Object{val:#EveryMatcher#}
                 Object{val:15}


assert.deepEqual(actual, loose(expected))
                 |       |     |
                 |       |     Object{b:5}
                 |       LooseMatcher{expected:#Object#}
                 Object{a:1,b:2,c:3}


assert.deepEqual(array, contains(val))
                 |      |        |
                 |      |        5
                 |      ContainsMatcher{expected:5}
                 [1,2,3]


assert.deepEqual(obj, primitive(prim))
                 |    |         |
                 |    |         "[object Arguments]"
                 |    PrimitiveMatcher{expected:"[object Arguments]"}
                 Object{}


assert.deepEqual(actual, expected)
                 |       |
                 |       Object{a:1,b:3,c:5}
                 Object{a:1,b:2,c:3}

Keywords

FAQs

Last updated on 03 May 2017

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc