utils/ts-src/get.test.ts
Martin Donnelly b0e843fd3e Added get function
Bumped to version 2.0.2
2020-11-17 16:31:00 +00:00

36 lines
547 B
TypeScript

import { get } from './get';
test('Get something from the object', function () {
const o = { a: 1, b: 2 };
expect(get(o, 'b')).toEqual(2);
});
test('Get something from a complex object', function () {
const o = {
a: 1,
b: {
c: 3,
d: {
e: 5
}
}
};
expect(get(o, 'b')).toEqual({ c: 3, d: { e: 5 } });
});
test('Get a deep item from a complex object', function () {
const o = {
a: 1,
b: {
c: 3,
d: {
e: 5
}
}
};
expect(get(o, 'b.d.e')).toEqual(5);
});