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
constassertUUID=assert.satisfies(value=>typeof value ==="string"&&value.match(uuidRegex))
63
+
constassertPositiveNumber= () =>assert.satisfies(value=>typeof value ==="number"&& value >0)
57
64
58
-
assert.deepEquals(getUsers(), [
65
+
assert.deepEquals(
66
+
// Actual value:
59
67
{
60
-
id:assertUUID(),
68
+
id:Math.random(),
61
69
name:"John Smith",
62
-
active:true
70
+
meta: {
71
+
isActive:true,
72
+
lastLogin:newDate("2019-04-29T12:31:00")
73
+
}
63
74
},
75
+
// Expectation:
64
76
{
65
-
id:assertUUID(),
66
-
name:"Jane Smith",
67
-
active:false
77
+
id:assertPositiveNumber(),
78
+
name:"John Smith",
79
+
meta: {
80
+
isActive:true,
81
+
lastLogin:newDate("2019-04-29T12:31:00")
82
+
}
68
83
}
69
84
])
70
85
```
71
86
72
87
### Spreading any()
73
88
74
-
Normally `deepEquals()` will fail if there are unexpected properties on the tested object. We can use `any()` with the object spread operator to allow additional properties to be present.
89
+
Normally `deepEquals()` will fail if there are properties on the tested object that don't exist on the expectation. We can use `any()` with the object spread operator to allow additional properties to be present.
75
90
76
91
`deepEquals()` will then only check the expected properties and ignore all other ones.
77
92
78
93
```js
79
94
import*asassertfrom"assert-deep"
80
95
81
-
assert.deepEquals(getUsers()[0], {
82
-
name:"John Smith",
83
-
active:true,
84
-
...assert.any()
85
-
})
96
+
assert.deepEquals(
97
+
// Actual value:
98
+
{
99
+
id:Math.random(),
100
+
name:"John Smith",
101
+
meta: {
102
+
isActive:true,
103
+
lastLogin:newDate("2019-04-29T12:31:00")
104
+
}
105
+
},
106
+
// Expectation:
107
+
{
108
+
id:assert.any(),
109
+
name:"John Smith",
110
+
...assert.any()
111
+
}
112
+
])
86
113
```
87
114
88
115
### Recursive objects
@@ -92,10 +119,10 @@ You can call `deepEquals()` in a custom `satisfies()` as well. This way you can
0 commit comments