summaryrefslogtreecommitdiff
path: root/harness
diff options
context:
space:
mode:
authorLeo Balter <leonardo.balter@gmail.com>2017-04-15 12:56:29 -0400
committerGitHub <noreply@github.com>2017-04-15 12:56:29 -0400
commite43ce56105a23c9a43ee26dab705b482c36df049 (patch)
tree07e55b0d38acf46dd9a54cf18b0ec07acb5416d2 /harness
parent1ba3a7c4a93fc93b3d0d7e4146f59934a896837d (diff)
downloadqtdeclarative-testsuites-e43ce56105a23c9a43ee26dab705b482c36df049.tar.gz
Add Verify Property harness (#979)
Diffstat (limited to 'harness')
-rw-r--r--harness/propertyHelper.js72
1 files changed, 71 insertions, 1 deletions
diff --git a/harness/propertyHelper.js b/harness/propertyHelper.js
index 6d67e4051..54fadd192 100644
--- a/harness/propertyHelper.js
+++ b/harness/propertyHelper.js
@@ -1,4 +1,74 @@
+function verifyProperty(obj, name, desc, options) {
+ assert(
+ arguments.length > 2,
+ 'verifyProperty should receive at least 3 arguments: obj, name, and descriptor'
+ );
+
+ var originalDesc = Object.getOwnPropertyDescriptor(obj, name);
+ var nameStr = String(name);
+
+ // Allows checking for undefined descriptor if it's explicitly given.
+ if (desc === undefined) {
+ assert.sameValue(
+ originalDesc,
+ undefined,
+ `obj['${nameStr}'] descriptor should be undefined`
+ );
+
+ // desc and originalDesc are both undefined, problem solved;
+ return true;
+ }
+
+ assert(
+ Object.prototype.hasOwnProperty.call(obj, name),
+ `obj should have an own property ${nameStr}`
+ );
+
+ assert.notSameValue(
+ desc,
+ null,
+ `The desc argument should be an object or undefined, null`
+ );
+
+ assert.sameValue(
+ typeof desc,
+ "object",
+ `The desc argument should be an object or undefined, ${String(desc)}`
+ );
+
+ var failures = [];
+
+ if (Object.prototype.hasOwnProperty.call(desc, 'enumerable')) {
+ if (desc.enumerable !== originalDesc.enumerable ||
+ desc.enumerable !== isEnumerable(obj, name)) {
+ failures.push(`descriptor should ${desc.enumerable ? '' : 'not '}be enumerable`);
+ }
+ }
+
+ if (Object.prototype.hasOwnProperty.call(desc, 'writable')) {
+ if (desc.writable !== originalDesc.writable ||
+ desc.writable !== isWritable(obj, name)) {
+ failures.push(`descriptor should ${desc.writable ? '' : 'not '}be writable`);
+ }
+ }
+
+ if (Object.prototype.hasOwnProperty.call(desc, 'configurable')) {
+ if (desc.configurable !== originalDesc.configurable ||
+ desc.configurable !== isConfigurable(obj, name)) {
+ failures.push(`descriptor should ${desc.configurable ? '' : 'not '}be configurable`);
+ }
+ }
+
+ assert.sameValue(failures.length, 0, failures.join('; '));
+
+ if (options && options.restore) {
+ Object.defineProperty(obj, name, originalDesc);
+ }
+
+ return true;
+}
+
function isConfigurable(obj, name) {
try {
delete obj[name];
@@ -11,7 +81,7 @@ function isConfigurable(obj, name) {
}
function isEnumerable(obj, name) {
- var stringCheck;
+ var stringCheck = false;
if (typeof name === "string") {
for (var x in obj) {