let timer = null

function waitForRequests(mockedRequests) {
  return new Promise(resolve => {
    if (mockedRequests.length < 1) {
      resolve()
      return
    }

    timer = setInterval(() => {
      const notYetCalled = mockedRequests.map(req => req.called()).
        filter(isCalled => !isCalled)
      if (notYetCalled.length < 1) {
        clearInterval(timer)
        resolve()
      }
    }, 100)
  })
}

export default waitForRequests

let timer = null

function waitForRequests(mockedRequests) {
  return new Promise(resolve => {
    if (mockedRequests.length < 1) {
      resolve()
      return
    }

    const allRequestsFinished = () => {
      const unfinishedRequests = mockedRequests.
        map(req => req.called()).filter(isCalled => !isCalled)
      return unfinishedRequests.length < 1
    }

    timer = setInterval(() => {
      if (allRequestsFinished()) {
        clearInterval(timer)
        resolve()
      }
    }, 100)
  })
}

export default waitForRequests

Refactor waitForRequests to be more clear
Refactor waitForRequests to be more clear
