jsunitexception.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2017 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. goog.provide('goog.testing.JsUnitException');
  15. goog.setTestOnly();
  16. goog.require('goog.testing.stacktrace');
  17. /**
  18. * @param {string} comment A summary for the exception.
  19. * @param {?string=} opt_message A description of the exception.
  20. * @constructor
  21. * @extends {Error}
  22. * @final
  23. */
  24. goog.testing.JsUnitException = function(comment, opt_message) {
  25. this.isJsUnitException = true;
  26. this.message = (comment ? comment : '') +
  27. (comment && opt_message ? '\n' : '') + (opt_message ? opt_message : '');
  28. this.stackTrace = goog.testing.stacktrace.get();
  29. // These fields are for compatibility with jsUnitTestManager.
  30. this.comment = comment || null;
  31. this.jsUnitMessage = opt_message || '';
  32. // Ensure there is a stack trace.
  33. if (Error.captureStackTrace) {
  34. Error.captureStackTrace(this, goog.testing.JsUnitException);
  35. } else {
  36. this.stack = new Error().stack || '';
  37. }
  38. };
  39. goog.inherits(goog.testing.JsUnitException, Error);
  40. /** @override */
  41. goog.testing.JsUnitException.prototype.toString = function() {
  42. return this.message;
  43. };