+ it('cannot be overwritten before being read if eventually not writable', function () {
+ lazy(o, 'p', initializer, {
+ writable: false,
+ });
+ try {
+ o.p = 'nope';
+ assert.fail('should disallow setting non-writable property');
+ } catch (e) {
+ assert(e instanceof TypeError, `expected 'TypeError', got ${e.name}`);
+ }
+ });
+
+ it('async initializer awkwardly needs await on all gets but technically works', async function () {
+ lazy(o, 'p', async () => {
+ called += 1;
+ return 'value';
+ });
+ const v = await o.p;
+ assert.strictEqual(called, 1);
+ assert.strictEqual(v, 'value');
+ });
+
+ it('prototypical lazy sets value on prototype by default', function () {
+ lazy(o, 'p', initializer);
+ o.id = 'proto';
+ const o1 = Object.create(o);
+ o1.id = 'o1';
+ const o2 = Object.create(o);
+ o2.id = 'o2';
+ const v1 = o1.p;
+ const v2 = o2.p;
+
+ assert.strictEqual(v1, 'value');
+ assert.strictEqual(v2, 'value');
+ assert.strictEqual(called, 1);
+ assert(!Object.hasOwnProperty.call(o1, 'p'));
+ assert(!Object.hasOwnProperty.call(o2, 'p'));
+ });
+
+ it('prototypical lazy sets value on inherited objects when requested', function () {
+ lazy(o, 'p', initializer, undefined, false);
+ o.id = 'proto';
+ const o1 = Object.create(o);
+ o1.id = 'o1';
+ const o2 = Object.create(o);
+ o2.id = 'o2';
+ const v1 = o1.p;
+ const v2 = o2.p;
+
+ assert.strictEqual(v1, 'value');
+ assert.strictEqual(v2, 'value');
+ assert.strictEqual(called, 2);
+ assert(Object.hasOwnProperty.call(o1, 'p'));
+ assert(Object.hasOwnProperty.call(o2, 'p'));
+ });
+
+}); // lazy
\ No newline at end of file