diff --git a/asyncforge.js b/asyncforge.js index 2ac45a4..00881f4 100644 --- a/asyncforge.js +++ b/asyncforge.js @@ -36,7 +36,10 @@ function memo (name) { function get () { const store = asyncLocalStorage.getStore() - return store?.[sym] + if (!store) { + throw new Error('asyncforge store is not initialized') + } + return store[sym] } function set (value) { diff --git a/test/do-not-start-memo.test.js b/test/do-not-start-memo.test.js index 13e6c52..0bd6307 100644 --- a/test/do-not-start-memo.test.js +++ b/test/do-not-start-memo.test.js @@ -8,7 +8,7 @@ test('memo without start', async (t) => { const p = tspl(t, { plan: 6 }) const a = memo() - p.deepStrictEqual(a(), undefined) + p.throws(() => a()) a.set({ value: 'bar' }) p.deepStrictEqual(a(), { value: 'bar' }) @@ -42,7 +42,7 @@ test('nested', async (t) => { const p = tspl(t, { plan: 5 }) const a = memo() - p.deepStrictEqual(a(), undefined) + p.throws(() => a()) a.set({ value: 'bar' }) p.deepStrictEqual(a(), { value: 'bar' })