Socket
Socket
Sign inDemoInstall

jest-expect-json

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    jest-expect-json

Jest testing with JSON


Version published
Weekly downloads
148
decreased by-63%
Maintainers
1
Install size
5.18 kB
Created
Weekly downloads
 

Readme

Source

Jest Expect JSON

Do you need to test objects against json strings? Does jest expect not have all the json matchers you deserve? Are your fetch tests looking real fragile with that block of json?

Import jest-expect-json into your tests now! Built on Jest expect matchers, `jest-expect-json add useful json testing to jest!

Setup

Add jest-expect-json to your test file like so:

import 'jest-expect-json';

Methods

jsonMatching

jsonMatching parses a json string for use with expect.

fetch('url', {
	method: 'POST',
	body: '{"some": "DATA", "more": "DATA!"}',
})
expect(fetch).toBeCalledWith('url', {
	method: 'POST',
	body: expect.jsonMatching({
		some: 'DATA',
		more: expect.stringContaining('!'),
	}),
});

jsonContaining

jsonContaining parses a json string and tests the data with the appropriate -containing method;

fetch('url', {
	method: 'POST',
	body: '{"some": "DATA", "more": "unchecked data"}',
})
expect(fetch).toBeCalledWith('url', {
	method: 'POST',
	body: expect.jsonContaining({ some: 'DATA' }),
});

Notes

Having trouble with type definitions? Append to your package.json like jest-extended:

"jest": {
  "setupFilesAfterEnv": [
    "jest-expect-json"
  ]
}

Keywords

FAQs

Last updated on 18 Feb 2021

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