-
Notifications
You must be signed in to change notification settings - Fork 468
logRoles now logs its output to console. #312
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
Conversation
API is unchanged, logRoles will still return the same string, but now also logs to the console. #311
Codecov Report
@@ Coverage Diff @@
## master #312 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 21 21
Lines 306 307 +1
Branches 64 64
=====================================
+ Hits 306 307 +1
Continue to review full report at Codecov.
|
logRoles now simply calls console.log.
This build is going to fail because of code coverage. As mentioned in #311, I'm not sure the best way to go about testing a console log side effect with void return value. logRoles is now just a call to console.log |
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.
Super duper 👍 Just fix the test and we should be good to go!
}) | ||
}) | ||
|
||
test('logRoles logs expected roles for various dom nodes', () => { |
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.
To test calls to console.log
you could do something like this:
jest.spyOn(console, 'log').mockImplementationOnce(() => {})
const {section} = setup()
logRoles(section)
expect(console.log).toHaveBeenCalledTimes(1)
expect(console.log.mock.calls[0][0]).toMatchSnapshot()
console.log.mockRestore()
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.
Nice! Looks like you figured it out without my help. Two things:
- Let's move that
addSnapshotSerializer
stuff to thesetup-env.js
file. - Make sure to call
mockRestore()
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.
Handled 5fefa1
src/__tests__/role-helpers.js
Outdated
jest.spyOn(console, 'log') | ||
logRoles(section) | ||
// eslint-disable-next-line no-console | ||
expect(console.log.mock.calls).toHaveLength(1) |
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.
This should probably be swapped with expect(console.log).toHaveBeenCalledTimes(1)
to improve any error message that may occur.
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.
Done 5fefa1
Test now only mocks console.log once. jest-serializer-ansi is now added to tests/setup-env.js so all snapshots benefit from it.
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.
Super. Thanks!
🎉 This PR is included in version 5.5.2 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
API is unchanged, logRoles will still return the same string, but now
also logs to the console.
#311
Initial fix for Issue #311
See discussion in #311
logRoles still returns a string, but now also logs its output to the console.
Checklist:
docs site