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

HTML-Reporter filters does not unhide all hidden suites #3110

Closed
4 tasks done
HeilTec opened this issue Nov 17, 2017 · 2 comments
Closed
4 tasks done

HTML-Reporter filters does not unhide all hidden suites #3110

HeilTec opened this issue Nov 17, 2017 · 2 comments

Comments

@HeilTec
Copy link

HeilTec commented Nov 17, 2017

Prerequisites

  • Checked that your issue isn't already filed by cross referencing issues with the common mistake label
  • Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
  • 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
  • Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with:
    node node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend avoiding the use of globally installed Mocha.

Description

HTML-Reporter filters does not unhide all hidden suites

Steps to Reproduce

Run tests using the html reporter - click on the passes / failures filters

Expected behavior: [What you expect to happen]
When clicking on a filter twice all suites should be visible

Actual behavior: [What actually happens]
Only the odd numbered of the hidden reappears

Reproduces how often: [What percentage of the time does it reproduce?]
100% It happens every time

Versions

Additional Information

While working on making a html-electron reporter I noticed this issue.
The function unhide() only un-hides the odd numbered hidden suites.

The problem is the mutation of the html collection as the parameters used for selecting the elements are removed from said elements.
This is the working solution I arrived at.

/**
 * Unhide .hidden suites.
 */
function unhide () {
  var els = document.getElementsByClassName('suite hidden');
  // as the search criterion is changed the elements are removed from the collection
  while (els[0]) { 
    els[0].className = els[0].className.replace('suite hidden', 'suite');
  }

// *** This only removes the odd numbered ***

  // for (var i = 0; i < els.length; ++i) {
  //   els[i].className = els[i].className.replace('suite hidden', 'suite');
  // }
}

@HeilTec
Copy link
Author

HeilTec commented Nov 17, 2017

If the above code smell is offending and appropriate transpiler is used for compatibility I like the functional approach:

function unhide () {
  var els = document.getElementsByClassName('suite hidden');

  [].reduce.call(els, (acc, el) => acc.concat([el]), [])
  .forEach(el => el.className = el.className.replace('suite hidden', 'suite'));
}

@ScottFreeCode
Copy link
Contributor

Closing as a duplicate of #2893, but if I've misunderstood and this is a different issue please let me know.

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

No branches or pull requests

2 participants