The goog.testing.ExpectedFailures Class

goog.testing.ExpectedFailures()

Helper class for allowing some unit tests to fail, particularly designed to mark tests that should be fixed on a given browser.

 var expectedFailures = new goog.testing.ExpectedFailures();

 function tearDown() {
   expectedFailures.handleTearDown();
 }

 function testSomethingThatBreaksInWebKit() {
   expectedFailures.expectFailureFor(goog.userAgent.WEBKIT);

   try {
     ...
     assert(somethingThatFailsInWebKit);
     ...
   } catch (e) {
     expectedFailures.handleException(e);
   }
 }
 

.expectFailureFor(condition, opt_message)

Register to expect failure for the given condition. Multiple calls to this function act as a boolean OR. The first applicable message will be used.

condition {boolean}
Whether to expect failure.
opt_message {string=}
Descriptive message of this expected failure.

.handleException(ex)

Handle an exception, suppressing it if it is a unit test failure that we expected.

ex {Error}
The exception to handle.

.handleTearDown()

Handle the tearDown phase of a test, alerting the user if an expected test was not suppressed.

.isExceptionExpected(ex)

Determines if the given exception was expected.

ex {Object}
The exception to check.
returns {boolean}
Whether the exception was expected.

.run(func, opt_lenient)

Run the given function, catching any expected failures.

func {Function}
The function to run.
opt_lenient {boolean=}
Whether to ignore if the expected failures didn't occur. In this case a warning will be logged in handleTearDown.