Skip to content

Commit 2c15bd8

Browse files
committed
t.has() and t.match() are not synonyms, they're different
Also, add docs for t.notHas and t.notHasStrict
1 parent c11ea4d commit 2c15bd8

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

docs/src/content/docs/api/asserts/index.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,30 @@ undefined` in the pattern to ensure that a field is not defined in the
256256
found object, but it will not differentiate between a missing property and
257257
a property set to `undefined`.
258258

259-
Note that `t.has()`, the un-strict version of this function, is an alias
260-
for `t.match()`.
259+
## t.notHasStrict(found, pattern, messsage, extra)
260+
261+
The inverse of `t.hasStrict()`. Verifies that the found object does not
262+
contain all of the provided fields, or if it does, that they are not the
263+
same values and/or types.
264+
265+
## t.has(found, pattern, message, extra)
266+
267+
Verify that the found object contains all of the provided fields, and that
268+
they coerce to the same values, even if the types do not match.
269+
270+
This does _not_ do advanced/loose matching based on constructor, regexp
271+
patterns, and so on, like `t.match()` does. You _may_ specify `key:
272+
undefined` in the pattern to ensure that a field is not defined in the
273+
found object, but it will not differentiate between a missing property and
274+
a property set to `undefined`.
275+
276+
Synonyms: `t.hasFields`, `t.includes`, `t.include`, `t.contains`
277+
278+
## t.notHas(found, pattern, message, extra)
279+
280+
The inverse of `t.has()`. Verifies that the found object does not contain
281+
all of the provided fields, or if it does, that they do not coerce to the
282+
same values.
261283

262284
## t.match(found, pattern, message, extra)
263285

@@ -280,8 +302,7 @@ set of required fields, but additional fields are ok.
280302
See [tcompare](http://npm.im/tcompare) for the full details on how this
281303
works.
282304

283-
Synonyms: `t.has`, `t.hasFields`, `t.matches`, `t.similar`, `t.like`,
284-
`t.isLike`, `t.includes`, `t.include`, `t.contains`
305+
Synonyms: `t.matches`, `t.similar`, `t.like`, `t.isLike`
285306

286307
## t.notMatch(found, pattern, message, extra)
287308

lib/synonyms.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ module.exports = multiword({
6464

6565
// found has the fields in wanted, string matches regexp
6666
match: [
67-
'has', 'hasFields', 'matches', 'similar', 'like', 'isLike',
68-
'includes', 'include', 'isSimilar', 'contains'
67+
'matches', 'similar', 'like', 'isLike', 'isSimilar'
68+
],
69+
70+
has: [
71+
'hasFields', 'includes', 'include', 'contains'
6972
],
7073

7174
notMatch: [

0 commit comments

Comments
 (0)