Skip to content
This repository has been archived by the owner on Jul 9, 2018. It is now read-only.

Jest Console: Add new matchers for console.log and console.info #137

Merged
merged 2 commits into from
Jun 26, 2018

Conversation

gziolo
Copy link
Member

@gziolo gziolo commented Jun 8, 2018

It was raised a few times in the past that @wordpress/jest-console supports only console.error and console.warn. We discussed that we should have a similar handling for console.log and console.info. This PR adds 4 new methods to @wordpress/jest-console package:

.toHaveInformed()

Use .toHaveInformed to ensure that console.info function was called.

Almost identical usage as .toHaveErrored().

.toHaveInformedWith( arg1, arg2, ... )

Use .toHaveInformedWith to ensure that console.info function was called with
specific arguments.

Almost identical usage as .toHaveErroredWith().

.toHaveLogged()

Use .toHaveLogged to ensure that console.log function was called.

Almost identical usage as .toHaveErrored().

.toHaveLoggedWith( arg1, arg2, ... )

Use .toHaveLoggedWith to ensure that console.log function was called with
specific arguments.

Almost identical usage as .toHaveErroredWith().

Testing

npm test should pass.

You can also add console.log and console.info in the source code or unit test to make sure it fails test that is using it when the matcher is not provided.

console.log( 'Test will fail' );

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:

expect( console ).toHaveLogged();

@@ -1,3 +1,7 @@
## Unreleased (2.0.0)
Copy link
Member Author

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
Copy link

codecov bot commented Jun 8, 2018

Codecov Report

Merging #137 into master will increase coverage by 0.19%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
packages/jest-console/src/supported-matchers.js 100% <100%> (ø)
packages/scripts/utils/index.js 97.22% <100%> (-0.08%) ⬇️
packages/jest-console/src/index.js 88.88% <100%> (+8.88%) ⬆️
packages/jest-console/src/matchers.js 91.66% <100%> (+0.75%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c24da3a...aaa6483. Read the comment docs.

@gziolo gziolo force-pushed the update/jest-console-methods branch from 452d06b to 44d601b Compare June 8, 2018 08:04
@gziolo gziolo force-pushed the update/jest-console-methods branch from 44d601b to 41749eb Compare June 8, 2018 08:05
@@ -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))
Copy link
Member

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.

Copy link
Member Author

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.

@gziolo gziolo merged commit 39314f7 into master Jun 26, 2018
@gziolo gziolo deleted the update/jest-console-methods branch June 26, 2018 05:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants