Socket
Book a DemoInstallSign in
Socket

jasmine2-json

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jasmine2-json

Add toEqualJson matcher to Jasmine 2.x

1.1.2
latest
Source
npmnpm
Version published
Weekly downloads
49
19.51%
Maintainers
1
Weekly downloads
 
Created
Source

Actions Status

Jasmine 2.x-3.x Json

This is similar to jasmine-json except it works with Jasmine 2.x or 3.x

toEqualJson matcher

Comparing large objects with jasmine works great until you get an error, when it dumps the entire object to the console in a completely human unreadable format.

This package adds a toEqualJson matcher to jasmine that will generate nice diffs on error. It will tell you which keys differ, and why.

# In your spec helper
require 'jasmine2-json'

# In your specs

describe "something", ->
  it "tests json", ->
    someObject =
      one: 1
      two:
        three: 5
        four: 4

    expect(someObject).toEqualJson
      one: 1
      two:
        three: 3
        four: 4
        five: 5

It will give you the path of the failure:

JSON is not equal:
two:
  actual:   has keys ["four","three"]
  expected: has keys ["five","four","three"]

If there are several errors, it will report all of them:

it "tests json", ->
    someObject =
      two:
        three:
          four:
            five: 4
            six: 5
            seven: 6

    expect(someObject).toEqualJson
      two:
        three:
          four:
            five: 5
            six: 6
            seven: 7

Reports:

JSON is not equal:
two.three.four.five:
  actual:   4
  expected: 5
two.three.four.six:
  actual:   5
  expected: 6
two.three.four.seven:
  actual:   6
  expected: 7

Keywords

jasmine

FAQs

Package last updated on 01 Jun 2022

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.