Commit 01cab452 authored by Vadym Gidulian's avatar Vadym Gidulian

Merge branch '1-fix-descriptors' into 'master'

Resolve "Fix property descriptors"

Closes #1

See merge request !1
parents 1900d971 45b38912
...@@ -17,11 +17,14 @@ function PromisedValue(initialValue) { ...@@ -17,11 +17,14 @@ function PromisedValue(initialValue) {
Object.defineProperties(this, { Object.defineProperties(this, {
isReady: { isReady: {
enumerable: true,
get() { get() {
return initialized; return initialized;
} }
}, },
value: { value: {
configurable: true,
enumerable: true,
get() { get() {
return value; return value;
}, },
...@@ -37,6 +40,7 @@ function PromisedValue(initialValue) { ...@@ -37,6 +40,7 @@ function PromisedValue(initialValue) {
} }
}, },
willBeReady: { willBeReady: {
enumerable: true,
get() { get() {
return willBeReady; return willBeReady;
} }
......
...@@ -32,3 +32,25 @@ test('Use new only', t => { ...@@ -32,3 +32,25 @@ test('Use new only', t => {
t.pass(); t.pass();
} }
}); });
test('Property descriptors', t => {
const v = new PV(42);
t.true(Object.keys(v).toString() === ['isReady', 'value', 'willBeReady'].toString());
Object.defineProperty(v, 'value', {
value: 42,
writable: false
});
t.is(v.value, 42);
try {
v.value = 43;
t.fail('An exception should be thrown');
} catch (e) {
t.pass();
}
delete v.value;
t.false(v.hasOwnProperty('value'));
t.true(Object.keys(v).toString() === ['isReady', 'willBeReady'].toString());
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment