Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missed case in "observe" type check #2919

Merged
merged 3 commits into from
Apr 8, 2018
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