You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/03-assertions.md
+49Lines changed: 49 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -207,6 +207,55 @@ Assert that `value` is deeply equal to `expected`. See [Concordance](https://git
207
207
208
208
Assert that `value` is not deeply equal to `expected`. The inverse of `.deepEqual()`.
209
209
210
+
### `.like(value, selector, message?)`
211
+
212
+
Assert that `value` is like `selector`. This is a variant of `.deepEqual()`, however `selector` does not need to have the same enumerable properties as `value` does.
213
+
214
+
Instead AVA derives a *comparable* object from `value`, based on the deeply-nested properties of `selector`. This object is then compared to `selector` using `.deepEqual()`.
215
+
216
+
Any values in `selector` that are not regular objects should be deeply equal to the corresponding values in `value`.
217
+
218
+
This is an experimental assertion for the time being. You need to enable it:
219
+
220
+
**`package.json`**:
221
+
222
+
```json
223
+
{
224
+
"ava": {
225
+
"nonSemVerExperiments": {
226
+
"likeAssertion": true
227
+
}
228
+
}
229
+
}
230
+
```
231
+
232
+
**`ava.config.js`**:
233
+
234
+
```js
235
+
exportdefault {
236
+
nonSemVerExperiments: {
237
+
likeAssertion:true
238
+
}
239
+
}
240
+
```
241
+
242
+
In the following example, the `map` property of `value` must be deeply equal to that of `selector`. However `nested.qux` is ignored, because it's not in `selector`.
243
+
244
+
```js
245
+
t.like({
246
+
map:newMap([['foo', 'bar']]),
247
+
nested: {
248
+
baz:'thud',
249
+
qux:'quux'
250
+
}
251
+
}, {
252
+
map:newMap([['foo', 'bar']]),
253
+
nested: {
254
+
baz:'thud',
255
+
}
256
+
})
257
+
```
258
+
210
259
### `.throws(fn, expectation?, message?)`
211
260
212
261
Assert that an error is thrown. `fn` must be a function which should throw. The thrown value *must* be an error. It is returned so you can run more assertions against it.
0 commit comments