1

I have a set of QUnit tests that run and pass on their own without any problems. However, when I recently added Blanket.js to measure javascript code coverage to help find the gaps in my testing, and all of a sudden I had several tests failing. Sprinkling in some alerts to help me locate what was happening. I found that all of my failing tests were ones using click events on functions that toggle between states. These tests were being toggled twice. I've looked into what would could cause double activation of the trigger, but in my code the functions aren't bound twice and I'm only including my javascript file once in the header.

I did notice in Firebug Blanket.js makes a GET request to the script I am testing against. Could the GET request be binding functions a second time or are there any other causes to this double activation?

Adam Bartz
  • 249
  • 3
  • 15
  • were you adding the data-cover attribute on the reference of your js file that you were testing? – jinmichaelr Nov 14 '14 at 04:20
  • @jinmichaelr Yes, the data-cover attribute is on the reference just after the src attribute. – Adam Bartz Nov 17 '14 at 19:01
  • I was thinking that you might have placed "data-cover" on the reference of your test scripts and not on the scripts that you were testing. Coz it happened that I misplaced "data-cover" on the wrong script, then BlanketJS triggered the test scripts twice. – jinmichaelr Nov 18 '14 at 04:48

2 Answers2

1

There's a lot going on under the hood of blanket. From what I can tell, it is essentially evaluating the code you tell it to. So anything that would just "run" will be evaluated once by loading in the DOM, and again when blanket evaluates it.

adambullmer
  • 952
  • 9
  • 29
  • Is it therefore ok to ignore failing tests when "Enable Coverage" is checked? this seems counterintuitive. I'd really like to have coverage enabled all the time with tests passing... – theUtherSide Sep 25 '15 at 23:39
1

Because Blanket will load this page scripts matched pattern in data-cover-only again to analayse script coverage, so that all your scripts executed a second time, which might bind your click event twice.

You can see it in the network pannel in Chrome Dev tools, and you will see requests like: enter image description here

Dickeylth
  • 828
  • 9
  • 15
  • Has anyone been able to solve this using `grunt-blanket`? This sounds like it could be a fix because it instruments the files first, then runs the tests against the instrumented files. This looks like it only has command-line output, however. https://github.com/alex-seville/grunt-blanket – theUtherSide Dec 22 '15 at 19:21