javascript - One failing test causes other async tests to fail -


i have basic karma/jasmine setup 1 test suite containing 2 tests. expect first test fail , second test pass.

describe("the system", function() {      it("should fail", function() {         expect(true).tobe(false);     });      it("should succeed", function(done) {         settimeout(function() {             expect(1).tobe(1);             done();         }, 10);     }); }); 

however, when run these tests in browser and click debug button open karma debug runner, see both tests failing, second test fails error message of first test. regular test run (i.e. not in karma debug runner) works expected.

the error message second test is:

uncaught expected true false.     @ usercontext.<anonymous> (http://localhost:9876/base/workingspec.js:4:22) thrown 

when disable or remove first test, second test passes.

why both tests fail in case? why second test fail error message of first test?


my test setup contains following packages/versions:

+-- jasmine-core@2.7.0 +-- karma@1.7.0 +-- karma-chrome-launcher@2.2.0 +-- karma-jasmine@1.1.0 `-- karma-jasmine-html-reporter@0.2.2 

at first thought bug, after research brilliant chrome devtools, seems expected behavior, @ least jasmine. may be, though, bug in karma framework.

in short, node_modules/karma/static/debug.js file (which js-file debug page) has these lines (i have karma v1.7.0):

for (var = 0; < result.log.length; i++) {   // throwing error without losing stack trace   (function (err) {     settimeout(function () {       throw err     })   })(result.log[i]) } 

if comment throw line, , restart karma server, you'll see console log messages, should expected: first fail, pass, , summary.


verbosely, bug in karma may in it's behavior report after each spec.

that what's happening here step step (i have version "jasmine-core": "^2.6.4", @ least in package.json file):

  1. jasmine runs first spec , fails;
  2. karma reports on in log , adds function, throws error stack (i assume reader knows asynchronous model in javascript, if not, must read in "effective javascript: 68 specific ways harness power of javascript" david herman, true gemstone book, or elsewhere). also, important, though i'm not sure, since haven't code deep, registers sort of "globalerror", since on next step
  3. jasmine runs second spec, , calls getjasminerequireobj().globalerrors function (jasmine.js:2204). "globalerror" detected , spec instantly becomes failure. asynchronous expect added stack after karma's function, one, throws error
  4. then first function (which throws error) starts execution, add throws. function called before jasmine asynchronous spec, since in debug.js there no time passed settimeout call:

    //notice absent time argument settimeout(function () { throw err })

  5. jasmine runs assync expect second spec , passes

  6. karma reports on second spec failure , adds error throwing (if not commented out, no error occurs , spec passes) stack
  7. karma's second error thrown

below screen shots numbers, put me illustrate steps list:

with throw not commented in debug.js file:

karma jasmine errors step step

and commented throw:

karma jasmine without throwing in debug.js file


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -