-
Notifications
You must be signed in to change notification settings - Fork 28
Jest Console: Add new matchers for console.log and console.info #137
Conversation
@@ -1,3 +1,7 @@ | |||
## Unreleased (2.0.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will also make wp-scripts test-unit-js
fail when code uses console.log
and console.info
, so we will have to bump @wordpress/scripts
- ideally we should align it with Babel 7 upgrade.
Codecov Report
@@ Coverage Diff @@
## master #137 +/- ##
==========================================
+ Coverage 67.04% 67.23% +0.19%
==========================================
Files 58 59 +1
Lines 698 699 +1
Branches 145 145
==========================================
+ Hits 468 470 +2
+ Misses 187 186 -1
Partials 43 43
Continue to review full report at Codecov.
|
452d06b
to
44d601b
Compare
44d601b
to
41749eb
Compare
packages/jest-console/CHANGELOG.md
Outdated
@@ -1,3 +1,7 @@ | |||
## Unreleased (2.0.0) | |||
|
|||
- Add new API methods `toHaveInformed`, `toHaveInformedWith`, `toHaveLogged` and `toHaveLoggedWith` ([137](https://github.com/WordPress/packages/pull/137)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should clarify that this is a breaking change ("Breaking:" prefix) and some hint to in what way it breaks / how consumers can update their code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I will add details.
It was raised a few times in the past that
@wordpress/jest-console
supports onlyconsole.error
andconsole.warn
. We discussed that we should have a similar handling forconsole.log
andconsole.info
. This PR adds 4 new methods to@wordpress/jest-console
package:.toHaveInformed()
Use
.toHaveInformed
to ensure thatconsole.info
function was called.Almost identical usage as
.toHaveErrored()
..toHaveInformedWith( arg1, arg2, ... )
Use
.toHaveInformedWith
to ensure thatconsole.info
function was called withspecific arguments.
Almost identical usage as
.toHaveErroredWith()
..toHaveLogged()
Use
.toHaveLogged
to ensure thatconsole.log
function was called.Almost identical usage as
.toHaveErrored()
..toHaveLoggedWith( arg1, arg2, ... )
Use
.toHaveLoggedWith
to ensure thatconsole.log
function was called withspecific arguments.
Almost identical usage as
.toHaveErroredWith()
.Testing
npm test
should pass.You can also add
console.log
andconsole.info
in the source code or unit test to make sure it fails test that is using it when the matcher is not provided.In addition, you can add expectation with matcher that is not used in the code to make sure that it fails because condition was not met: