Skip to content
This repository has been archived by the owner on Mar 25, 2022. It is now read-only.

Commit

Permalink
Handle regular expressions in deepEqual assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanmanning committed Jun 29, 2013
1 parent 5683136 commit 0c45d01
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/proclaim.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@
if (expected instanceof Date && actual instanceof Date) {
return actual.getTime() === expected.getTime();
}
if (actual instanceof RegExp && expected instanceof RegExp) {

This comment has been minimized.

Copy link
@stephenmathieson

stephenmathieson Jun 30, 2013

Contributor

just my ocd kicking in, but if actual instanceof RegExp, but !(expected instanceof RegExp), there's no need to perform any other checks.

this goes for Date comparison too.

imo, the node assert pattern makes sense in this case:

if (actual instanceof Whatever) {
  if (!(expected instanceof Whatever)) {
    return false
  }
  // check properties and such
}
return (
actual.source === expected.source &&
actual.global === expected.global &&
actual.multiline === expected.multiline &&
actual.lastIndex === expected.lastIndex &&
actual.ignoreCase === expected.ignoreCase
);
}
if (typeof actual !== 'object' && typeof expected !== 'object') {
return actual == expected;
}
Expand Down Expand Up @@ -163,7 +172,7 @@
if (typeof expected === 'string') {
return actual.message === expected;
}
if (Object.prototype.toString.call(expected) === '[object RegExp]') {
if (expected instanceof RegExp) {
return expected.test(actual.message);
}
if (actual instanceof expected) {
Expand Down

0 comments on commit 0c45d01

Please sign in to comment.