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

Improve is-element.test.js #84

Merged
merged 3 commits into from
Aug 31, 2019

Conversation

mroderick
Copy link
Member

This PR makes a few improvements to is-element.test.js

Purpose (TL;DR)

Improve test isolation in order to allow future work to re-order tests.

Background

During work in #82 I discovered that this test is sensitive to load order.

Solution

  • Increase test isolation be ensuring that is-element.js detects the DOM set up in the test harness.
  • Also improve readability of the test file.

How to verify - mandatory

  1. Observe all tests pass

Checklist for author

  • npm run lint passes
  • References to standard library functions are cached.

@mroderick mroderick force-pushed the improve-is-element-test branch 2 times, most recently from 19d59be to 6a84f51 Compare August 31, 2019 11:45
@mroderick mroderick changed the title Improve is-element.test.s Improve is-element.test.js Aug 31, 2019
During some other work it became clear that this test does not have
good isolation, ad it would fail because `is-element.js` would not
detect a DOM when it was loaded as a side effect of loading `samsam` by
other tests.

The solution is to ensure that this test prepares the environment
properly, by deleting `is-element.js` from `require.cache` and setting
up a DOM, before loading `is-element.js`.

See:
* https://nodejs.org/api/modules.html#modules_require_cache
* http://derpturkey.com/reload-module-with-node-js-require/
* Apply white space to make code easily read as Arrange, Act, Assert
* Rename variable to make it clearer what it is
This improves the readability of tests because the natural reading
direction of English is left to right. Readers will no longer have to
scan back and forth in the first argument to `it` to figure out when this
expectation applies.
@mroderick mroderick force-pushed the improve-is-element-test branch from 6a84f51 to 1399b4a Compare August 31, 2019 11:51
@mroderick mroderick merged commit 4a2cec5 into sinonjs:master Aug 31, 2019
@mroderick mroderick deleted the improve-is-element-test branch August 31, 2019 11:53
@codecov
Copy link

codecov bot commented Aug 31, 2019

Codecov Report

Merging #84 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #84   +/-   ##
=======================================
  Coverage   98.51%   98.51%           
=======================================
  Files          17       17           
  Lines         472      472           
=======================================
  Hits          465      465           
  Misses          7        7
Flag Coverage Δ
#unit 98.51% <ø> (ø) ⬆️

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 674268c...1399b4a. Read the comment docs.

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

Successfully merging this pull request may close these issues.

1 participant