title: Testing nested functions in jest without return
body: <p>I have a notfications.js file which I want to write jest tests for. Can someone tell me how to approach the test cases for this.</p>
  
  <pre><code>import { store } from 'react-notifications-component';
  
  /**
   * Helper function to add a notification anywhere.
   * @param {*} title string
   * @param {*} message string
   * @param {*} type  string of success, danger, info, default, warning
   */
  const addNotification = (title, message, type) =&gt; {
    const options = {
      title,
      message,
      type,
      insert: 'top',
      container: 'top-right',
      animationIn: ['animated', 'fadeIn'],
      animationOut: ['animated', 'fadeOut'],
    };
  
    store.addNotification({
      ...options,
      dismiss: {
        duration: 5000,
        onScreen: true,
        pauseOnHover: true,
      },
    });
  };
  
  export default addNotification;
  </code></pre>
  
  <p>I read the jest documentation and read about mock functions but wasn't able to figure a lot out. First time trying to write a unit test.</p>
  
  <blockquote>
    <p><strong>Solution</strong>:
    I was able to do the testing by creating a spy for the store using jest spyOn.
    My test was: </p>
  </blockquote>
  
  <pre><code>const params = {
    title: 'test',
    type: 'success',
    message: 'this is a test notification!',
  };
  
  describe('addNotification', () =&gt; {
    beforeAll(() =&gt; {
      jest.spyOn(store, 'addNotification');
    });
  
    afterAll(() =&gt; {
      jest.restoreAllMocks();
    });
  
    test('calls store.addNotification()', () =&gt; {
      addNotification(params.title, params.message, params.type);
      expect(store.addNotification).toHaveBeenCalled();
    });
  
  });
  </code></pre>
  
  <p><strong>Note</strong>: <strong>Please refer to the answer provided by</strong> @slideshowp2 <strong>it is a better</strong> <strong>solution.</strong></p>