API Docs for: 3.17.2
Show:

File: test/js/ComparisonFailure.js

  1. /**
  2. * ComparisonFailure is subclass of Error that is thrown whenever
  3. * a comparison between two values fails. It provides mechanisms to retrieve
  4. * both the expected and actual value.
  5. *
  6. * @param {String} message The message to display when the error occurs.
  7. * @param {Object} expected The expected value.
  8. * @param {Object} actual The actual value that caused the assertion to fail.
  9. * @namespace Test
  10. * @extends AssertionError
  11. * @module test
  12. * @class ComparisonFailure
  13. * @constructor
  14. */
  15. YUITest.ComparisonFailure = function (message, expected, actual){
  16.  
  17. //call superclass
  18. YUITest.AssertionError.call(this, message);
  19.  
  20. /**
  21. * The expected value.
  22. * @type Object
  23. * @property expected
  24. */
  25. this.expected = expected;
  26.  
  27. /**
  28. * The actual value.
  29. * @type Object
  30. * @property actual
  31. */
  32. this.actual = actual;
  33.  
  34. /**
  35. * The name of the error that occurred.
  36. * @type String
  37. * @property name
  38. */
  39. this.name = "ComparisonFailure";
  40.  
  41. };
  42.  
  43. //inherit from YUITest.AssertionError
  44. YUITest.ComparisonFailure.prototype = new YUITest.AssertionError;
  45.  
  46. //restore constructor
  47. YUITest.ComparisonFailure.prototype.constructor = YUITest.ComparisonFailure;
  48.  
  49. /**
  50. * Returns a fully formatted error for an assertion failure. This message
  51. * provides information about the expected and actual values.
  52. * @method getMessage
  53. * @return {String} A string describing the error.
  54. */
  55. YUITest.ComparisonFailure.prototype.getMessage = function(){
  56. return this.message + "\nExpected: " + this.expected + " (" + (typeof this.expected) + ")" +
  57. "\nActual: " + this.actual + " (" + (typeof this.actual) + ")";
  58. };
  59.