Created
March 6, 2012 09:29
Revisions
-
ebi created this gist
Mar 6, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ /** * Assert that an object has all of the same properties and property values * as the expected one. It doesn't consider prototype properties. * @param {Object} expected The object with all expected properties and values. * @param {Object} actual The object to inspect. * @param {String} message (Optional) The message to display if the assertion fails. * @method areSame * @static */ areSame: function (expected, actual, message) { YUITest.Assert._increment(); if ('object' !== typeof actual) { throw new YUITest.UnexpectedValue(YUITest.Assert._formatMessage(message, "Value should be an object."), actual); } if ('object' !== typeof expected) { throw new YUITest.UnexpectedValue(YUITest.Assert._formatMessage(message, "Value should be an object."), expected); } for (var key in expected) { if (expected.hasOwnProperty(key)) { if ('object' === typeof actual[key] || 'object' === typeof expected[key]) { YUITest.ObjectAssert.areSame(expected[key], actual[key], message); } else if (actual[key] !== expected[key]) { throw new YUITest.ComparisonFailure(YUITest.Assert._formatMessage(message, "Values should be equal for property " + key), expected[key], actual[key]); } } } for (key in actual) { if (actual.hasOwnProperty(key) && 'undefined' === typeof expected[key]) { throw new YUITest.ComparisonFailure(YUITest.Assert._formatMessage(message, 'Property is not defined on actual object ' + key)); } } }