Open tommy-mitchell opened 7 months ago
Currently like
is a partial deepEqual
, selecting from the actual
(first argument) just those properties that exist in the expected
(second argument). How would we do that if expected
contains a regular expression value?
Currently
like
is a partialdeepEqual
, selecting from theactual
(first argument) just those properties that exist in theexpected
(second argument). How would we do that ifexpected
contains a regular expression value?
Maybe:
If expected.prop
is a RegExp
and actual.prop
is a string
:
Check if actual.prop
matches expected.prop
If false
, fail the test. The current descriptors (string vs regex) can stay as-is:
- str: 'string',
+ str: /string/,
If expected.prop
is a RegExp
and actual.prop
is a RegExp
:
If expected.prop
is a string
and actual.prop
is a RegExp
:
I agree that this looks useful, and your logic makes sense, but I don't immediately see how this could be implemented. Don't let that stop you though 😉
It may also technically be a breaking change, in that if you've written an existing assertion expecting a regular expression, and your actual value changes to a string, that happens to match… the test passes when it shouldn't. OK that seems unlikely.
The
message
property int.throws
is really ergonomic - it can be astring
,RegExp
, or even a function.t.like
should be just as ergonomic with strings:A motivating example is trying to convert this test from
npm-user
to uset.like
: