Skip to content

Commit

Permalink
Scoping highlighting tags to the mocha element
Browse files Browse the repository at this point in the history
I'm not sure whether I'm missing an edge case or not, but this solves my issue and it makes sense to me that this is what we would want it to be anyway. Everything should be scoped to the `#mocha` element anyway. My use case is I have a collection of components and I have tests for them. I have a site that shows the component, an example, and the test. The example and test is interactive and runs on the page. Without this change, mocha will highlight all my other code tags on the page which messes things up. Here's an example of this change working on my page: http://kent.doddsfamily.us/kcd-angular/#/kcd-dynamic-attr#spec (see the spec toward the bottom)
  • Loading branch information
Kent C. Dodds committed Aug 28, 2014
1 parent da0bfb2 commit 414d793
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ function highlight(js) {
*/

exports.highlightTags = function(name) {
var code = document.getElementsByTagName(name);
var code = document.getElementById('mocha').getElementsByTagName(name);
for (var i = 0, len = code.length; i < len; ++i) {
code[i].innerHTML = highlight(code[i].innerHTML);
}
Expand Down

2 comments on commit 414d793

@nevir
Copy link

@nevir nevir commented on 414d793 Sep 15, 2014

Choose a reason for hiding this comment

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

Edge case for ya: If you're using something other than the default web reporter, this is going to blow up. For ex: https://github.com/eeroan/WebConsole-reporter

#1363

@kentcdodds
Copy link

Choose a reason for hiding this comment

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

Does my change make a difference in that case? Does this code even run with that reporter? Seems like there's no need to highlight tags in the console......

Please sign in to comment.