[proposal] expect(fn).toLog(str, level = 'log')
See original GitHub issue🚀 Feature Proposal
Proposal is to create “sibling” methods to .toThrow
, .toThrowErrorMatchingSnapshot()
& .toThrowErrorMatchingInlineSnapshot
that would test if console[level]
has been called during the fn
invocation
Motivation
Make testing console.log/console.warn/console.error calls easier - testing it with jest.fn()
/mocks is somewhat cumbersome.
Example
test('getItemProps logs a helpful error when no object is given', () => {
expect(() =>
render(
<Downshift>
{({getItemProps}) => (
<div>
<span {...getItemProps()} />
</div>
)}
</Downshift>,
),
).toLogMatchingSnapshot('error')
})
Pitch
IMHO it’s as helpful as toThrow
methods and could be included in the core.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
The right way to describe your strengths in a proposal
You should anticipate the evaluation forms so that the evaluator can copy and paste your descriptions of your strengths right onto their forms....
Read more >OUTDOOR TED WEEMS
co Ruissitellon over chore. wm offer. to the Arvawiesen ... four weeks, alldinee house record for scale ... ¢O-Level off 1,11 con.
Read more >Full text of "Historical collections of Louisiana and Florida
Full text of "Historical collections of Louisiana and Florida : including translations of original manuscripts relating to their discovery and settlement, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @Andarist I’m not sure I understand this as a matcher, its unclear that the matcher is actually watching the
console
to make assertions against it.This behaviour feels closer to Jest’s
jest.useFakeTimers()
, perhaps ajest.useFakeConsole()
which mocks all of the available methods would be more suitable?That way you can use all of the existing matchers maybe something like:
This is a little more verbose, but it is explicit over what you are doing.
An issue with wrapping the log code as a function that is ran by the matcher is that you may want to use the returned value (in this example the rendered component) in another assertions and now you would not be able to do that.
Let me know your thoughts? 😄
EDIT: cc/ @thymikee @SimenB @rickhanlonii I’d be curious to know your thoughts too 😉
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.