import { get } from './get';

describe('get', () => {
  test('should return the nested property if it exists', () => {
    const obj = {
      foo: {
        bar: {
          baz: 'Hello, World!'
        }
      }
    };

    expect(get(obj, 'foo.bar.baz')).toBe('Hello, World!');
  });

  test('should return the default value if the nested property does not exist', () => {
    const obj = {
      foo: {
        bar: {
          baz: 'Hello, World!'
        }
      }
    };

    expect(get(obj, 'foo.bar.qux', 'Default')).toBe('Default');
  });

  test('should return the default value if the object is null or undefined', () => {
    expect(get(null, 'foo.bar.baz', 'Default')).toBe('Default');
    expect(get(undefined, 'foo.bar.baz', 'Default')).toBe('Default');
  });

  test('should return the default value if the nested property is null or undefined', () => {
    const obj = {
      foo: {
        bar: {
          baz: null
        }
      }
    };

    expect(get(obj, 'foo.bar.baz', 'Default')).toBe('Default');
    expect(get(obj, 'foo.bar.qux', 'Default')).toBe('Default');
  });
});
