Skip to content
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

fix: Add default onAction prop #382

Merged

Conversation

kYem
Copy link
Contributor

@kYem kYem commented Jun 11, 2020

What does it do?

PropTypes define onAction property as optional, however in class its
used unconditionally. Trying to click the action without passing onAction handler cause type error.

Fixes #380

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • Updated documentation (if applicable)
  • Added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • My changes generate no new warnings

PropTypes define onAction property as optional, however in class its
used unconditionally.
@coveralls
Copy link

coveralls commented Jun 11, 2020

Pull Request Test Coverage Report for Build 1459

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 93.995%

Totals Coverage Status
Change from base Build 1456: 0.0%
Covered Lines: 601
Relevant Lines: 622

💛 - Coveralls

const { tree } = t.context
const wrapper = mount(<DropdownTreeSelect id={dropdownId} data={tree} showDropdown="initial" />)
wrapper.find('i.fa-ban').simulate('click')
t.pass()
Copy link
Collaborator

Choose a reason for hiding this comment

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

t.pass?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not entirely sure what I need to check here 🤔
The test is only checking if the click event does not trigger error, therefore it pass.

Any suggestions what would be correct test for it otherwise?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well, there is literally no checks/assertions in this test. It adds no value. I'm not sure if there's a way to check for those type of warnings during a test run. If we can't find a way to ensure that a specific warning is not emitted, then I'd rather not have this test.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think one way we could check for this is spy console.warn or console.error (whichever is emitted by React) and then check that it doesn't get called.

You can remove your default prop and this test should fail - which would confirm that this approach works :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, because it's actual JavaScript TypeError, nothing to do with React itself, it already fails by default without any checks, if default prop is removed, like this:

index › notifies on action without onAction handler

....../javascript/react-dropdown-tree-select/src/index.js:216

   215:   onAction = (nodeId, action) => {                                   
   216:     this.props.onAction(this.treeManager.getNodeById(nodeId), action)
   217:   }                                                                  

  Error thrown in test:

  TypeError {
    message: '_this.props.onAction is not a function',
  }

I changed from pass() to spy for console error, but honestly I don't see any value in it.

Let me know if this acceptable now

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well pass is of no value. This test actually checks and will warn in future if we break it again. I'll check it and merge (mostly looks good).

@mrchief
Copy link
Collaborator

mrchief commented Jun 11, 2020

@all-contributors Please add @kYem for bug, code

@allcontributors
Copy link
Contributor

@mrchief

I've put up a pull request to add @kYem! 🎉

@stale
Copy link

stale bot commented Jul 25, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jul 25, 2020
@kYem
Copy link
Contributor Author

kYem commented Jul 25, 2020

@mrchief Is this going to get merged?

@stale stale bot removed the stale label Jul 25, 2020
@codeclimate
Copy link

codeclimate bot commented Jul 25, 2020

Code Climate has analyzed commit 4d7a6a0 and detected 0 issues on this pull request.

View more on Code Climate.

@mrchief mrchief merged commit db0e59c into dowjones:develop Jul 25, 2020
@github-actions
Copy link

🎉 This PR is included in version 2.3.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

m4theushw pushed a commit to m4theushw/react-dropdown-tree-select that referenced this pull request Sep 20, 2020
* fix: Add default onAction prop

PropTypes define onAction property as optional, however in class its
used unconditionally.

* fix: Add console error spy check

Co-authored-by: Hrusikesh Panda <mrchief@users.noreply.github.com>
@kYem kYem deleted the bugfix/380-on-action-default-prop-missing branch April 7, 2022 10:17
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.

TypeError: n.props.onAction is not a function
3 participants