Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/createStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export default function createStore(reducer, preloadedState, enhancer) {
* emission of values from the observable.
*/
subscribe(observer) {
if (typeof observer !== 'object') {
if (typeof observer !== 'object' || observer === null) {
throw new TypeError('Expected the observer to be an object.')
}

Expand Down
8 changes: 6 additions & 2 deletions test/createStore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,11 +629,15 @@ describe('createStore', () => {

expect(function() {
obs.subscribe()
}).toThrow()
}).toThrowError(new TypeError('Expected the observer to be an object.'))

expect(function() {
obs.subscribe(null)
}).toThrowError(new TypeError('Expected the observer to be an object.'))

expect(function() {
obs.subscribe(() => {})
}).toThrow()
}).toThrowError(new TypeError('Expected the observer to be an object.'))

expect(function() {
obs.subscribe({})
Expand Down