Skip to content

V4 get in fix #1362

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

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ TODO
/gh-pages
/npm
/dist
tags
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove this unrelated change?

44 changes: 44 additions & 0 deletions __tests__/getIn.ts
Original file line number Diff line number Diff line change
@@ -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.
*/

///<reference path='../resources/jest.d.ts'/>

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);
});

});
2 changes: 1 addition & 1 deletion src/CollectionImpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down