Skip to content
This repository has been archived by the owner on Nov 27, 2020. It is now read-only.

Ensure onToggle is called when on is controlled but setOnState is called #18

Merged
merged 3 commits into from
Mar 24, 2018
Merged

Conversation

bslinger
Copy link
Contributor

@bslinger bslinger commented Mar 24, 2018

What: Fix a bug introduced in #17 that prevents onToggle from being called when the internal setOnState is called.

Why: When on is controlled, onToggle should be called either when the controlled prop is change, or when the internal toggle actually occurs

How: I added a check in setOnState to compare the current on with the new state and call onToggle if necessary.

Checklist:

  • Documentation N/A
  • Tests
  • Ready to be merged
  • Added myself to contributors table

Copy link
Owner

@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.

This looks good to me. Thanks!

@kentcdodds
Copy link
Owner

Looks like we need another test to get our code coverage goal. Could you please do that?

@bslinger
Copy link
Contributor Author

Ah, just noticed that. Strange, shouldn't line 72 be covered since setOnState is being called in several tests? Sorry, I'm not as familiar with jest as I'd like to be!

@kentcdodds
Copy link
Owner

If you want to look at the coverage report, open coverage/lcov-report/index.html locally in your browser 👍 that could help.

@codecov
Copy link

codecov bot commented Mar 24, 2018

Codecov Report

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

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #18   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           1      1           
  Lines          18     20    +2     
  Branches        7      8    +1     
=====================================
+ Hits           18     20    +2
Impacted Files Coverage Δ
src/index.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 7aa7805...5299b74. Read the comment docs.

@bslinger
Copy link
Contributor Author

Ah thanks, I see, I had to make sure both branches of the if were covered - looks like this did the trick!

Copy link
Owner

@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.

Sweet! Thanks!

@kentcdodds kentcdodds merged commit f8e32df into kentcdodds:master Mar 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants