Skip to content

Commit

Permalink
test(get): add tests for get function
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Hamilton committed Dec 5, 2018
1 parent e388847 commit 773a2ca
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/get.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import get from '../src/get';

describe('get', () => {
test('should return the default value (undefined) if the object specified isn\'t an object', () => {
const got = get('test');

expect(got).toBeUndefined();
});

test('should return the default value (undefined) if the object specified is empty', () => {
const got = get({});

expect(got).toBeUndefined();
});

test('should return the default value when the object doesn\'t have the path specified', () => {
const a = {
a: 1,
};
const got = get(a, 'b');

expect(got).toBeUndefined();
});

test('should return the specified default value', () => {
const a = {
a: 1,
};
const got = get(a, 'b', 'default');

expect(got).toBe('default');
});

test('should return the specified default value when the path is dot notation', () => {
const a = {
a: {
b: 1,
},
};
const got = get(a, 'a.b');

expect(got).toBe(1);
});
});

0 comments on commit 773a2ca

Please # to comment.