Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented the .toMatchObject(object) assertion #1843

Merged
merged 5 commits into from
Nov 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ expect all the time. That's what you use `expect` for.
- [`.toEqual(value)`](#toequalvalue)
- [`.toHaveLength(number)`](#tohavelengthnumber)
- [`.toMatch(regexp)`](#tomatchregexp)
- [`.toMatchObject(object)`](#tomatchobjectobject)
- [`.toMatchSnapshot()`](#tomatchsnapshot)
- [`.toThrow()`](#tothrow)
- [`.toThrowError(error)`](#tothrowerrorerror)
Expand Down Expand Up @@ -597,6 +598,36 @@ describe('an essay on the best flavor', () => {

This matcher also accepts a string, which it converts to a RegExp.

### `.toMatchObject(object)`

Use `.toMatchObject` to check that a javascript object matches a subset of the properties of an object.

```js
const houseForSale = {
bath: true,
kitchen: {
amenities: ['oven', 'stove', 'washer'],
area: 20,
wallColor: 'white'
},
bedrooms: 4
}
const desiredHouse = {
bath: true,
kitchen: {
amenities: ['oven', 'stove', 'washer'],
wallColor: 'white'
}
}

describe('looking for a new house', () => {
it('the house has my desired features', () => {
expect(houseForSale).toMatchObject(desiredHouse);
}
}
```


### `.toMatchSnapshot()`

This ensures that a React component matches the most recent snapshot. Check out [the React + Jest tutorial](https://facebook.github.io/jest/docs/tutorial-react.html) for more information on snapshot testing.
Expand Down
Loading