Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thinkmill/jest-expect-contain-deep
Assert deeply nested values in Jest
https://github.com/thinkmill/jest-expect-contain-deep
assertion deep jest matcher test
Last synced: 8 days ago
JSON representation
Assert deeply nested values in Jest
- Host: GitHub
- URL: https://github.com/thinkmill/jest-expect-contain-deep
- Owner: Thinkmill
- License: mit
- Created: 2017-09-21T11:21:54.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-12T09:53:09.000Z (about 2 years ago)
- Last Synced: 2025-01-31T10:15:10.700Z (13 days ago)
- Topics: assertion, deep, jest, matcher, test
- Language: JavaScript
- Size: 319 KB
- Stars: 66
- Watchers: 5
- Forks: 5
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jest-expect-contain-deep
> Assert deeply nested values in [Jest](https://facebook.github.io/jest/)
## Installation
```sh
yarn add --dev jest-expect-contain-deep
```## Usage
**Before:**
```js
const containDeep = require('jest-expect-contain-deep');test('values', () => {
let massiveObject = getMassiveObject();
expect(massiveObject.foo).toBe(expect.arrayContaining([1, 2]));
expect(massiveObject.bar.prop).toBe(true);
expect(massiveObject.baz).toContain('bar');
});test('spies', () => {
doSomething();
expect(mySpy.mock.calls[0][0].foo).toBe(expect.arrayContaining([1, 2]));
expect(mySpy.mock.calls[0][0].bar.prop).toBe(true);
expect(mySpy.mock.calls[0][0].baz).toContain('bar');
});
```**After:**
```js
const containDeep = require('jest-expect-contain-deep');test('values', () => {
expect(getMassiveObject()).toEqual(containDeep({
foo: [1, 2],
bar: { prop: true },
baz: expect.stringContaining('bar'),
}));
});test('spies', () => {
doSomething();
expect(mySpy).toHaveBeenCalledWith('arg1', containDeep({
foo: [1, 2],
bar: { prop: true },
baz: expect.stringContaining('bar'),
}));
});
```