diff --git a/.gitignore b/.gitignore index 4c2930a8c2..fafca0b743 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ TODO /gh-pages /npm /dist +tags diff --git a/__tests__/getIn.ts b/__tests__/getIn.ts new file mode 100644 index 0000000000..3127b6381d --- /dev/null +++ b/__tests__/getIn.ts @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/// + +import * as jasmineCheck from 'jasmine-check'; +jasmineCheck.install(); + +import { fromJS } from '../'; + +describe('getIn', () => { + it('should allow getIn past null values', () => { + console.warn = jest.genMockFunction(); + + const m = fromJS({ a: { b: { c: null }}}); + + expect(m.getIn(['a', 'b', 'c', 'd'], 'notSetValue')).toBe('notSetValue'); + expect(console.warn.mock.calls.length).toBe(0); + }); + + it('shouldn\'t allow getIn past defined values without .get', () => { + console.warn = jest.genMockFunction(); + + const m = fromJS({ a: { b: { c: 'fail point' }}}); + + m.getIn(['a', 'b', 'c', 'd'], 'notSetValue'); + expect(console.warn.mock.calls.length).toBe(1); + }); + + // hasIn calls getIn + it('should allow hasIn past null values', () => { + console.warn = jest.genMockFunction(); + + const m = fromJS({ a: { b: { c: null }}}); + + expect(m.hasIn(['a', 'b', 'c', 'd'])).toBeFalsy(); + expect(console.warn.mock.calls.length).toBe(0); + }); + +}); diff --git a/src/CollectionImpl.js b/src/CollectionImpl.js index e7f3eefa1d..9ae9842558 100644 --- a/src/CollectionImpl.js +++ b/src/CollectionImpl.js @@ -861,7 +861,7 @@ function getIn(value, notSetValue, searchKeyPath, reportBadKeyPath) { return notSetValue; } value = value.get(keyPath[i++], NOT_SET); - if (value === NOT_SET) { + if (value === NOT_SET || value === null || value === undefined) { return notSetValue; } }