diff --git a/packages/injectable-react/src/asyncComputed/asyncComputed.js b/packages/injectable-react/src/asyncComputed/asyncComputed.js index d1105434..0ead6e25 100644 --- a/packages/injectable-react/src/asyncComputed/asyncComputed.js +++ b/packages/injectable-react/src/asyncComputed/asyncComputed.js @@ -1,3 +1,4 @@ +import { noop } from 'lodash/fp'; import { computed, createAtom, observable, runInAction, untracked } from 'mobx'; const neutralizeObsoletePromiseSymbol = Symbol.for( @@ -9,7 +10,7 @@ export default (getObservedPromise, pendingValue) => { const pendingBox = observable.box(false); - let neutralizeObsoletePromise; + let neutralizeObsoletePromise = noop; const syncValueBox = observable.box(pendingValue, { name: 'sync-value-box-for-async-computed', diff --git a/packages/injectable-react/src/asyncComputed/asyncComputed.test.js b/packages/injectable-react/src/asyncComputed/asyncComputed.test.js index b6f9f9e4..ec53cbb4 100644 --- a/packages/injectable-react/src/asyncComputed/asyncComputed.test.js +++ b/packages/injectable-react/src/asyncComputed/asyncComputed.test.js @@ -20,6 +20,14 @@ describe('asyncComputed', () => { }, 'some-pending-value'); }); + it('given invalidated before observation, when observed, does not throw', () => { + someAsyncComputed.invalidate(); + + expect(() => { + observe(someAsyncComputed.value, () => {}); + }).not.toThrow(); + }); + describe('when only status is observed but not value', () => { beforeEach(() => { observe(someAsyncComputed.pending, () => {});