Skip to content

Conversation

michaellasky
Copy link
Collaborator

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:

  • Documentation added to the
    docs site
  • Typescript definitions updated
  • Tests
  • Ready to be merged

API is unchanged, logRoles will still return the same string, but now
also logs to the console.

#311
@codecov-io
Copy link

codecov-io commented Jul 10, 2019

Codecov Report

Merging #312 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #312   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          21     21           
  Lines         306    307    +1     
  Branches       64     64           
=====================================
+ Hits          306    307    +1
Impacted Files Coverage Δ
src/role-helpers.js 100% <100%> (ø) ⬆️

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 2846a8e...5fefa10. Read the comment docs.

logRoles now simply calls console.log.
@michaellasky
Copy link
Collaborator Author

michaellasky commented Jul 10, 2019

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

Copy link
Member

@kentcdodds kentcdodds left a 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', () => {
Copy link
Member

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()

Copy link
Member

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:

  1. Let's move that addSnapshotSerializer stuff to the setup-env.js file.
  2. Make sure to call mockRestore()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled 5fefa1

jest.spyOn(console, 'log')
logRoles(section)
// eslint-disable-next-line no-console
expect(console.log.mock.calls).toHaveLength(1)
Copy link
Member

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.

Copy link
Collaborator Author

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

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super. Thanks!

@kentcdodds kentcdodds merged commit 170978b into master Jul 10, 2019
@kentcdodds kentcdodds deleted the pr/issue_311_logroles_doesnt_log branch July 10, 2019 16:15
@kentcdodds
Copy link
Member

🎉 This PR is included in version 5.5.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants