Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F7535563
test_define_property_edge_cases.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
test_define_property_edge_cases.js
View Options
// Test edge cases for Object.defineProperty()
console
.
log
(
"Test 1: Error when called with < 3 arguments"
);
try
{
Object
.
defineProperty
({},
"foo"
);
console
.
log
(
"FAIL: Should have thrown error"
);
}
catch
(
e
)
{
console
.
log
(
"PASS: Correctly throws error"
);
}
console
.
log
(
"\nTest 2: Error when first argument is not an object"
);
try
{
Object
.
defineProperty
(
42
,
"foo"
,
{
value
:
1
});
console
.
log
(
"FAIL: Should have thrown error"
);
}
catch
(
e
)
{
console
.
log
(
"PASS: Correctly throws error for non-object"
);
}
console
.
log
(
"\nTest 3: Error when descriptor is not an object"
);
try
{
Object
.
defineProperty
({},
"foo"
,
"not an object"
);
console
.
log
(
"FAIL: Should have thrown error"
);
}
catch
(
e
)
{
console
.
log
(
"PASS: Correctly throws error for non-object descriptor"
);
}
console
.
log
(
"\nTest 4: Error when mixing data and accessor descriptors"
);
try
{
Object
.
defineProperty
({},
"foo"
,
{
value
:
42
,
get
:
function
()
{
return
0
;
}
});
console
.
log
(
"FAIL: Should have thrown error"
);
}
catch
(
e
)
{
console
.
log
(
"PASS: Correctly throws error for mixed descriptors"
);
}
console
.
log
(
"\nTest 5: Can define property with just value"
);
const
obj5
=
{};
Object
.
defineProperty
(
obj5
,
"test"
,
{
value
:
100
});
console
.
log
(
"PASS: Property defined with just value:"
,
obj5
.
test
);
console
.
log
(
"\nTest 6: Cannot define __proto__ property"
);
try
{
Object
.
defineProperty
({},
"__proto__"
,
{
value
:
{}
});
console
.
log
(
"FAIL: Should have thrown error"
);
}
catch
(
e
)
{
console
.
log
(
"PASS: Correctly prevents __proto__ definition"
);
}
console
.
log
(
"\nTest 7: Works with arrays"
);
const
arr
=
[
1
,
2
,
3
];
Object
.
defineProperty
(
arr
,
"myProp"
,
{
value
:
"test"
});
console
.
log
(
"PASS: Works with arrays:"
,
arr
.
myProp
);
console
.
log
(
"\nTest 8: Works with functions"
);
function
myFunc
()
{}
Object
.
defineProperty
(
myFunc
,
"customProp"
,
{
value
:
42
});
console
.
log
(
"PASS: Works with functions:"
,
myFunc
.
customProp
);
console
.
log
(
"\nAll edge case tests completed!"
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Jun 17, 12:07 PM (1 d, 13 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
523811
Default Alt Text
test_define_property_edge_cases.js (1 KB)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment