-
-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add .toLog() matcher #202
base: main
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #202 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 109 117 +8
Lines 554 634 +80
Branches 97 109 +12
=====================================
+ Hits 554 634 +80
Continue to review full report at Codecov.
|
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.
Hey there,
Thanks for raising this, and I think its a really really cool idea.
I have a question around the API we use here, we could stick with the implementation proposed where we pass what we expect and then the console function expected to be called, or we could have an explicit matcher for each console function e.g.
expect(someFunctionCall).toConsoleLog('some log')
expect(someFunctionCall).toConsoleInfo('some info')
expect(someFunctionCall).toConsoleError('some error')
That way we can setup the spies on initiation rather than run time so it only gets setup once rather than for every use of the matcher? How does this sound?
Look forward to hearing from you soon, this is awesome 🥳
src/matchers/toLog/predicate.js
Outdated
import { equals } from 'expect/build/jasmine_utils'; | ||
|
||
export default (fn, expected, consoleMethod) => { | ||
const spy = jest.spyOn(console, consoleMethod); |
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.
if we set up the spy here I can imagine we could incure larger performance implications than if it wasn't set at run time, but ill comment on that in my main response 😇
Thanks a lot for the input @benjaminkay93, really like having an explicit matcher for each console method (PR is updated to reflect this). A few thoughts,
|
Nit: I would adjust the matcher method to be more human-readable: |
|
@williamrchr Thanks for having a look, did some more updates to this 🙂 |
Hi, all But there is a question, Why this process stoped and Maybe when will this PR is probably be merged? Look forward to knowing more about this, and Thanks a lot! |
|
@@ -0,0 +1,17 @@ | |||
import { equals } from 'expect/build/jasmine_utils'; |
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.
I assume this path used to be correct, but it's now jasmineUtils
instead of jasmine_utils
.
This might need a bit of tweaking so consider it a WIP. Thought I put it up here to see if something like this would be useful, input is much appreciated 🙂
What
This PR adds a new matcher for asserting that a callback function outputs a message to the console. The given console method is mocked when running the callback, so nothing is actually printed to the console.
Why
I sometimes find myself wanting to assert that some function prints a message to the console. Like for instance checking that some information is printed, or that a deprecation warning is printed when calling a certain method. This matcher would be convenient for such scenarios.
Instead of doing something like:
We could do
Housekeeping
yarn contributor
)