import { sendMessage } from '../sendMessage';

describe('Utils/Function/sendMessage', () => {
    test(
        'sendMessage calls the given function on the subject with the correct args, ' +
            'and returns the original result',
        () => {
            const testObj = {
                foo: jest.fn(() => 'result'),
            };
            const result = sendMessage(testObj, 'foo', 'test argument');
            expect(result).toBe('result');
            expect(testObj.foo).toHaveBeenCalledWith('test argument');
        }
    );
    test('sendMessage not errors if the first arg is not an object, or the function does not exist', () => {
        expect(() => sendMessage(false)).not.toThrowError();
        expect(() => sendMessage({}, 'nonExistingFunction')).not.toThrowError();
    });
});
