react-shortcuts
react-shortcuts copied to clipboard
Refactor test suite
This pull request improves the test suite's structure, readability and coverage.
Changes
Testing dependencies
- Upgrade test dependencies to the latest versions to take advantage of the latest syntax and performance
- Extract setup code for the test suite into a
test/setup.jsfile - Introduce a
mocha.optsconfiguration file for easier configuration of how the test suite runs - Commented each testing dependencies import and explained its role in the test suite
Structure
- Abstract constants used across many tests, like key codes into support files for re-use
- Introduce helper functions to perform tasks that are repeated throughout the test suite
- Introduced common contexts for tests where possible
- Moved setup code into
beforeEachblocks of common contexts where possible - Separate out the testing of
<Shortcuts />into multiple files for easier navigation
Syntax
- Use JSX rather than
React.createElementandReact.DOM - Abstract the use of
React.findDOMNodeto a single place, so it will be easier to swap out at a later point (I couldn't figure out how to remove the deprecated method completely)
Coverage
- Extend the test suite to more completely describe the behaviour of the package based on execution paths in the code and test cases that illustrate important differences in behaviour in particular situations
Limitations
- I could still not figure out the real role of the
isolateprop through writing tests and reading the source code - this may be because of the way events are simulated in the test suite or something else I am not getting. - The test suite was extended to be description rather than prescriptive (it documents how the package seems to behave, not how it should necessarily behave). So it may encode some bugs as expected behaviour (because I am unclear about the intended behaviour in some situations).
Conflicts
- This pull request does cover most of the changes made in #43. I used it (and the review comments) as inspiration in refactoring some of the test suite. It does not completely obviate the changes made in that pull request, however, as no changes to the source code has been made in this pull request.