mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2026-09-25 19:40:42 +02:00
44 lines
1.0 KiB
TypeScript
44 lines
1.0 KiB
TypeScript
import { getValueByPath } from 'n8n-design-system/utils';
|
|
|
|
describe('getValueByPath()', () => {
|
|
const object = {
|
|
id: '1',
|
|
name: 'Richard Hendricks',
|
|
address: {
|
|
city: 'Palo Alto',
|
|
state: 'California',
|
|
country: 'United States',
|
|
},
|
|
};
|
|
|
|
it('should return direct field from object', () => {
|
|
const path = 'name';
|
|
|
|
expect(getValueByPath(object, path)).toEqual(object.name);
|
|
});
|
|
|
|
it('should return nested field from object', () => {
|
|
const path = 'address.country';
|
|
|
|
expect(getValueByPath(object, path)).toEqual(object.address.country);
|
|
});
|
|
|
|
it('should return undefined if direct field does not exist', () => {
|
|
const path = 'other';
|
|
|
|
expect(getValueByPath(object, path)).toEqual(undefined);
|
|
});
|
|
|
|
it('should return undefined if nested field does not exist', () => {
|
|
const path = 'address.other';
|
|
|
|
expect(getValueByPath(object, path)).toEqual(undefined);
|
|
});
|
|
|
|
it('should return undefined if path does not exist', () => {
|
|
const path = 'other.other';
|
|
|
|
expect(getValueByPath(object, path)).toEqual(undefined);
|
|
});
|
|
});
|