266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * The ObjectAssert object provides functions to test JavaScript objects
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * for a variety of cases.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @namespace Test
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @class ObjectAssert
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * Asserts that an object has all of the same properties
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * and property values as the other.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {Object} expected The object with all expected properties and values.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {Object} actual The object to inspect.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {String} message (Optional) The message to display if the assertion fails.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @method areEqual
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @deprecated
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith var expectedKeys = YUITest.Object.keys(expected),
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith //first check keys array length
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Object should have " + expectedKeys.length + " keys but has " + actualKeys.length));
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith //then check values
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith throw new YUITest.ComparisonFailure(YUITest.Assert._formatMessage(message, "Values should be equal for property " + name), expected[name], actual[name]);
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * Asserts that an object has a property with the given name.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {String} propertyName The name of the property to test.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {Object} object The object to search.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {String} message (Optional) The message to display if the assertion fails.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @method hasKey
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @deprecated Use ownsOrInheritsKey() instead
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith hasKey: function (propertyName, object, message) {
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith YUITest.ObjectAssert.ownsOrInheritsKey(propertyName, object, message);
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * Asserts that an object has all properties of a reference object.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {Array} properties An array of property names that should be on the object.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {Object} object The object to search.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {String} message (Optional) The message to display if the assertion fails.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @method hasKeys
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @deprecated Use ownsOrInheritsKeys() instead
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith hasKeys: function (properties, object, message) {
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith YUITest.ObjectAssert.ownsOrInheritsKeys(properties, object, message);
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * Asserts that a property with the given name exists on an object's prototype.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {String} propertyName The name of the property to test.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {Object} object The object to search.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {String} message (Optional) The message to display if the assertion fails.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @method inheritsKey
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith inheritsKey: function (propertyName, object, message) {
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith if (!(propertyName in object && !object.hasOwnProperty(propertyName))){
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Property '" + propertyName + "' not found on object instance."));
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * Asserts that all properties exist on an object prototype.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {Array} properties An array of property names that should be on the object.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {Object} object The object to search.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {String} message (Optional) The message to display if the assertion fails.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @method inheritsKeys
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith inheritsKeys: function (properties, object, message) {
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith if (!(propertyName in object && !object.hasOwnProperty(properties[i]))){
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Property '" + properties[i] + "' not found on object instance."));
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * Asserts that a property with the given name exists on an object instance (not on its prototype).
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {String} propertyName The name of the property to test.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {Object} object The object to search.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {String} message (Optional) The message to display if the assertion fails.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @method ownsKey
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith ownsKey: function (propertyName, object, message) {
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Property '" + propertyName + "' not found on object instance."));
4969799abcdbfb7be34c4bbe20c2051bd50e1391Adam Moore * Asserts that all properties exist on an object instance (not on its prototype).
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {Array} properties An array of property names that should be on the object.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {Object} object The object to search.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {String} message (Optional) The message to display if the assertion fails.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @method ownsKeys
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith ownsKeys: function (properties, object, message) {
4969799abcdbfb7be34c4bbe20c2051bd50e1391Adam Moore YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Property '" + properties[i] + "' not found on object instance."));
4969799abcdbfb7be34c4bbe20c2051bd50e1391Adam Moore * Asserts that an object owns no properties.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {Object} object The object to check.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {String} message (Optional) The message to display if the assertion fails.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @method ownsNoKeys
b99f5105fd25efdbea655f7a50b225bace962ad2Luke Smith YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Object owns " + count + " properties but should own none."));
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * Asserts that an object has a property with the given name.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {String} propertyName The name of the property to test.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {Object} object The object to search.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {String} message (Optional) The message to display if the assertion fails.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @method ownsOrInheritsKey
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith ownsOrInheritsKey: function (propertyName, object, message) {
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Property '" + propertyName + "' not found on object."));
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * Asserts that an object has all properties of a reference object.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {Array} properties An array of property names that should be on the object.
266bfbd67fc220029bdadabd3c49e733f9f39360Luke Smith * @param {Object} object The object to search.
6af8358a6bd80bcc795828ce62c1ecd22daab6a1Luke Smith * @param {String} message (Optional) The message to display if the assertion fails.
6af8358a6bd80bcc795828ce62c1ecd22daab6a1Luke Smith * @method ownsOrInheritsKeys
6af8358a6bd80bcc795828ce62c1ecd22daab6a1Luke Smith ownsOrInheritsKeys: function (properties, object, message) {
6af8358a6bd80bcc795828ce62c1ecd22daab6a1Luke Smith YUITest.Assert.fail(YUITest.Assert._formatMessage(message, "Property '" + properties[i] + "' not found on object."));