67546

QUnit asyncTest does not continue after error

Question:

How can I tell QUnit to consider errors during asyncTest as test failures and continue to next test?

here is an example which QUnit stops running after a ReferenceError: <a href="http://jsfiddle.net/bakhshi/7VfSb/" rel="nofollow">jsfiddle</a>

Answer1:

Errors in asynchronous tests die silently if they arise while QUnit isn't officially running.

The simplest solution is to wrap every asyncTest contents in a try/catch block that propagates any errors <em>after</em> restarting QUnit. We don't actually have to pollute the code with a million try/catches--we can decorate your existing methods automagically.

For example:

// surrounds any function with a try/catch block to propagate errors to QUnit when // called during an asyncTest function asyncTrier(method) { return function () { try{ // if the method runs normally, great! method(); } catch (e) { // if not, restart QUnit and pass the error on QUnit.start(); throw new (e); } }; } QUnit.asyncTest("sample", 1, function () { setTimeout(asyncTrier(function(){ var foo = window.nonexistentobj.toString() + ""; // throws error QUnit.ok("foo defined", !!foo) QUnit.start(); }), 1000); });

Forked your Fiddle, with a sample wrapping method to automatically apply such a try/catch around every asynchronous block: <a href="http://jsfiddle.net/bnMWd/4/" rel="nofollow">http://jsfiddle.net/bnMWd/4/</a>

(<strong>Edit</strong>: updated per comments.)

Recommend

  • Returning an error message to an end user upon exception in WebApi methods
  • PoCo validation on Textbox for Integer DataType
  • append value to environment variable on builder call
  • brush extents not working as expected
  • Emulate C# lock statement in C++
  • Adding a new attribute on source code that propagates until MC level in LLVM?
  • How do I revert sys.stdout.close()?
  • Restart app on force kill
  • ASP Error 0223 - TypeLib Not Found, intermittent, resolved after IIS restart
  • Firefox extension testing and developing - I'm confused
  • Time taken for Hadoop job to execute
  • Best HTML5 structure for a layout where the title/header is outside the article tag
  • How to make SASS put relative paths in its output
  • Manually Timing out a C# Thread
  • Responsive left sidebar open close
  • Ruby 1.8.6 Array#uniq not removing duplicate hashes
  • Prevent page break in text block with iText, XMLWorker
  • Problem with Django using Apache2 (mod_wsgi), Occassionally is “unable to import from module” for no
  • Configure Spring's MappingJacksonHttpMessageConverter
  • C++ friend class std::vector
  • SyntaxError: (irb):26: both block arg and actual block given
  • AppleScript : find open tab in safari by name and open it
  • How can I sort a a table with VBA with given text condition?
  • Converting a WriteableBitmap image ToArray in UWP
  • azure media services - The request body is too large and exceeds the maximum permissible limit
  • Sencha Touch 2.0 Controller refs attribute not working?
  • Play WS (2.2.1): post/put large request
  • Get data from AJAX - How to
  • Reading JSON from a file using C++ REST SDK (Casablanca)
  • Initializer list vs. initialization method
  • Why value captured by reference in lambda is broken? [duplicate]
  • Spring security and special characters
  • Check if a string to interpolate provides expected placeholders
  • javascript inside java/jsp code
  • Trying to switch camera back to front but getting exception
  • RestKit - RKRequestDelegate does not exist
  • Traverse Array and Display in markup
  • Free memory of cv::Mat loaded using FileStorage API
  • Angular 2 constructor injection vs direct access
  • Programmatically clearing map cache