title: Using Jest to mock named imports
body: <p>I have a 'notifications.js' module that looks a bit like this:</p>
  <pre class="lang-js prettyprint-override"><code>import { Notifications, Permissions } from 'expo'
  
  export function setLocalNotification(storage = AsyncStorage) {
    return storage
      .getItem(NOTIFICATION_KEY)
      .then(JSON.parse)
      .then(data =&gt; {
        if (data === null) {
          return Permissions.askAsync(
            Permissions.NOTIFICATIONS
          ).then(({ status }) =&gt; {
            if (status === 'granted') {
              Notifications.cancelAllScheduledNotificationsAsync()
              ...etc.
  </code></pre>
  <p>In my test, I want to mock Permissions and Notifications so I can do something like this in notifications.spec.js:</p>
  <pre class="lang-js prettyprint-override"><code>import { setLocalNotification } from './notifications'
  import mockAsyncStorage from '../mock/AsyncStorage'
  
  it('correctly cancels pending notifications', done =&gt; {
    setLocalNotification(mockAsyncStorage).then(done())
    expect(Permissions.askAsync).toBeCalled()
    expect(Notifications.cancelAllScheduledNotificationsAsync)
      .toBeCalled()
  })
  </code></pre>
  <p>I've tried various things using <code>jest.mock</code> and <code>jest.setMock</code> but I can't seem to get this working. How do I go about mocking these named imports in the desired way? For instance, I've tried this:</p>
  <pre class="lang-js prettyprint-override"><code>jest.setMock('Permissions', () =&gt; ({
    askAsync: jest
      .fn()
      .mockImplementationOnce(() =&gt; ({ status: 'granted' }))
  }))
  </code></pre>
  <p>But that doesn't work. It throws</p>
  <pre><code>'module Permissions cannot be found from notifications.spec.js'
  </code></pre>
  <p>And if I try to mock the entire expo module, the mocked functions <code>expect().toBeCalled()</code> returns false.</p>