From dacaec1e8389ba18588f4ba7a389f2aa6b36929a Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Wed, 31 Jan 2018 14:53:37 -0800 Subject: [PATCH] fix(proxy): don't throw on missing property BREAKING CHANGE: Given that simple access of a non-existent property on a JavaScript object will return `undefined`, `promwrap` should follow suit. --- index.js | 1 - test/test-basics.js | 18 +++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 5ef2de3..5ce8de8 100644 --- a/index.js +++ b/index.js @@ -20,7 +20,6 @@ const handler = { target.cache.set(name, val) return val } - throw new Error(`Module has no property named ${name}`) } } diff --git a/test/test-basics.js b/test/test-basics.js index 73abdfc..411e0a1 100644 --- a/test/test-basics.js +++ b/test/test-basics.js @@ -15,12 +15,16 @@ test('test basics', t => { ]) }) -test('test error', t => { +test('unknown property', t => { t.plan(2) - try { - console.log(promwrap(_module).notfound) - } catch (e) { - t.type(e, 'Error') - t.type(e.message, (`Module has no property named notfound`)) - } + t.same(_module.foo, void 0) + let mod = promwrap(_module) + t.same(mod.foo, void 0) +}) + +test('unknown function', t => { + t.plan(2) + t.throws(() => _module.foo()) + let mod = promwrap(_module) + t.throws(() => mod.foo()) })