Skip to content

Commit

Permalink
Add specs for utils.getIn (jaredpalmer#2093)
Browse files Browse the repository at this point in the history
Add specs for utils.getIn
  • Loading branch information
jaredpalmer authored Dec 12, 2019
2 parents 48dd0c7 + 0a35414 commit 448e3e7
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ yarn.lock
!/yarn.lock

website/translated_docs
website/build/
website/build
website/yarn.lock
website/node_modules
website/i18n/*
website/i18n
Binary file removed examples/.DS_Store
Binary file not shown.
21 changes: 21 additions & 0 deletions packages/formik/test/utils.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
isEmptyArray,
setIn,
getIn,
setNestedObjectValues,
isPromise,
getActiveElement,
Expand Down Expand Up @@ -147,6 +148,26 @@ describe('utils', () => {
});
});

describe('getIn', () => {
const obj = {
a: {
b: 2,
},
};

it('gets a value by array path', () => {
expect(getIn(obj, ['a', 'b'])).toBe(2);
});

it('gets a value by string path', () => {
expect(getIn(obj, 'a.b')).toBe(2);
});

it('return "undefined" if value was not found using given path', () => {
expect(getIn(obj, 'a.z')).toBeUndefined();
});
});

describe('setIn', () => {
it('sets flat value', () => {
const obj = { x: 'y' };
Expand Down
Binary file removed website/.DS_Store
Binary file not shown.
Binary file removed website/build/formik/.DS_Store
Binary file not shown.
Binary file removed website/build/formik/img/.DS_Store
Binary file not shown.
Binary file removed website/static/.DS_Store
Binary file not shown.
Binary file removed website/static/img/.DS_Store
Binary file not shown.

0 comments on commit 448e3e7

Please sign in to comment.