Skip to content

Commit

Permalink
Only run wrapMatchers() if we've received a custom message that needs…
Browse files Browse the repository at this point in the history
… proxying. Avoids speed cost if not using custom message
  • Loading branch information
Coridyn authored and mattphillips committed Sep 8, 2022
1 parent 75fa9d0 commit 0772823
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/withMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@ const wrapMatchers = (matchers, customMessage) => {
export default expect => {
// proxy the expect function
let expectProxy = Object.assign(
(actual, customMessage) => wrapMatchers(expect(actual), customMessage), // partially apply expect to get all matchers and chain them
(actual, customMessage) => {
let matchers = expect(actual); // partially apply expect to get all matchers and chain them
if (customMessage) {
// only pay the cost of proxying matchers if we received a customMessage
matchers = wrapMatchers(matchers, customMessage);
}

return matchers;
},
expect // clone additional properties on expect
);

Expand Down

0 comments on commit 0772823

Please sign in to comment.