import { printError, printWarning } from './console';

/* eslint-disable no-console */

describe('printError', () => {
  it('prints an error to the console', () => {
    jest.spyOn(console, 'error').mockReturnValue();
    printError('test text');
    expect(console.error).toHaveBeenCalled();
    expect(console.error)
      .toHaveBeenCalledWith('storyshare-sui-react-components: test text');
  });

  it('copes if console.error is missing', () => {
    const errorBackup = console.error;
    delete console.error;
    printError('test text');
    console.error = errorBackup;
  });
});

describe('printWarning', () => {
  it('prints a warning to the console', () => {
    jest.spyOn(console, 'warn').mockReturnValue();
    printWarning('test text');
    expect(console.warn).toHaveBeenCalled();
    expect(console.warn)
      .toHaveBeenCalledWith('storyshare-sui-react-components: test text');
  });

  it('copes if console.warn is missing', () => {
    const warnBackup = console.warn;
    delete console.warn;
    printWarning('test text');
    console.warn = warnBackup;
  });
});
