Skip to content

Commit f81ef8d

Browse files
zerobiastimdorr
authored andcommitted
Fix missed case in "observe" type check (#2919)
* Make sure that assumed TypeError would be thrown * Check that ThrowError would be thrown in case of null observer object * Add null check for subscribe method
1 parent a804207 commit f81ef8d

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/createStore.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export default function createStore(reducer, preloadedState, enhancer) {
234234
* emission of values from the observable.
235235
*/
236236
subscribe(observer) {
237-
if (typeof observer !== 'object') {
237+
if (typeof observer !== 'object' || observer === null) {
238238
throw new TypeError('Expected the observer to be an object.')
239239
}
240240

test/createStore.spec.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -629,11 +629,15 @@ describe('createStore', () => {
629629

630630
expect(function() {
631631
obs.subscribe()
632-
}).toThrow()
632+
}).toThrowError(new TypeError('Expected the observer to be an object.'))
633+
634+
expect(function() {
635+
obs.subscribe(null)
636+
}).toThrowError(new TypeError('Expected the observer to be an object.'))
633637

634638
expect(function() {
635639
obs.subscribe(() => {})
636-
}).toThrow()
640+
}).toThrowError(new TypeError('Expected the observer to be an object.'))
637641

638642
expect(function() {
639643
obs.subscribe({})

0 commit comments

Comments
 (0)