Skip to content

Commit

Permalink
Fix missed case in "observe" type check (#2919)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
zerobias authored and timdorr committed Apr 8, 2018
1 parent a804207 commit f81ef8d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
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

0 comments on commit f81ef8d

Please sign in to comment.