Exciting news!Announcing our $4.6M Series Seed. Learn more
Socket
LoveBlogFAQ
Install
Log in

jest-expect-json

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Issues
File Explorer

Advanced tools

jest-expect-json

Jest testing with JSON

    0.1.1latest

Version published
Maintainers
1
Yearly downloads
5,679
increased by1100.63%

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

Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc