vitebonus / closure-library

Automatically exported from code.google.com/p/closure-library
0 stars 0 forks source link

goog.asserts.AssertionError is not compatible in ExpectedFailures.js #575

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago

What steps will reproduce the problem?
1. Create a UnitTest with ExpectedFailures and test with 
goog.asserts.AssertionError
2. Run the test

What is the expected output? What do you see instead?
The test throws an error that AssertionError is not expected.
In some cases it's very useful to catch such AssertError, i.e. for classes that 
have goog.asserts.assert() implemented with additional errormessage parameters.

I made a temporary local fix for this in ExpectedFailures.isExceptionExpected():

{code}
/**
 * Determines if the given exception was expected.
 * @param {Object} ex The exception to check.
 * @return {boolean} Whether the exception was expected.
 */
goog.testing.ExpectedFailures.prototype.isExceptionExpected = function(ex) {

  //return this.expectingFailure_ && ex instanceof goog.testing.JsUnitException;

   //Extended for goog.asserts.AssertionError!
  return this.expectingFailure_
      && (ex instanceof goog.testing.JsUnitException || ex instanceof goog.asserts.AssertionError);
};
{code}

What version of the product are you using? On what operating system?

Please provide any additional information below.

Note: we cannot accept patches without the contributor license agreement
being signed. See http://code.google.com/p/closure-
library/wiki/Contributors for more info.

Original issue reported on code.google.com by atng...@gmail.com on 24 Jul 2013 at 9:14

GoogleCodeExporter commented 8 years ago
This is very old, but isExceptionExpected is specifically for assertions you 
expect to fail in *tests*. Hence, the JsUnitException. AssertionError is just 
the exception type  goog.asserts in your business logic. If you want to verify 
a method throws in a test, just use assertThrows 
https://github.com/google/closure-library/blob/master/closure/goog/testing/asser
ts.js#L252

Original comment by joelt...@google.com on 5 Aug 2015 at 9:24