Replace mayHaveProperty with verifyProperty

This commit is contained in:
André Bargull 2017-12-21 12:08:19 -08:00 committed by Rick Waldron
parent d249979bc9
commit 20ea611db7
2 changed files with 13 additions and 19 deletions

View File

@ -856,22 +856,6 @@ function testProperty(obj, property, valid) {
}
/**
* Tests whether the named property of the given object, if present at all, has a valid value
* and the default attributes of the properties of an object literal.
* @param {Object} obj the object to be tested.
* @param {string} property the name of the property
* @param {Function|Array} valid either a function that tests value for validity and returns a boolean,
* an array of valid values.
* @exception if the property is present and has an invalid value.
*/
function mayHaveProperty(obj, property, valid) {
if (obj.hasOwnProperty(property)) {
testProperty(obj, property, valid);
}
}
/**
* Tests whether the given object has the named property with a valid value
* and the default attributes of the properties of an object literal.

View File

@ -7,7 +7,7 @@ description: >
Tests that the object returned by
Intl.Collator.prototype.resolvedOptions has the right properties.
author: Norbert Lindenberg
includes: [testIntl.js]
includes: [testIntl.js, propertyHelper.js]
---*/
var actual = new Intl.Collator().resolvedOptions();
@ -41,5 +41,15 @@ mustHaveProperty(actual, "usage", ["sort"]);
mustHaveProperty(actual, "sensitivity", ["variant"]);
mustHaveProperty(actual, "ignorePunctuation", [false]);
mustHaveProperty(actual, "collation", collations);
mayHaveProperty(actual, "numeric", [true, false]);
mayHaveProperty(actual, "caseFirst", ["upper", "lower", "false"]);
// "numeric" is an optional property.
if (actual.hasOwnProperty("numeric")) {
assert.notSameValue([true, false].indexOf(actual.numeric), -1);
verifyProperty(actual, "numeric", {writable: true, enumerable: true, configurable: true});
}
// "caseFirst" is an optional property.
if (actual.hasOwnProperty("caseFirst")) {
assert.notSameValue(["upper", "lower", "false"].indexOf(actual.caseFirst), -1);
verifyProperty(actual, "caseFirst", {writable: true, enumerable: true, configurable: true});
}