import { createStore, applyMiddleware } from 'redux'
import sagaMiddleware from '../../src'
import * as io from '../../src/effects'

test('should not interpret returned effect. fork(() => effectCreator())', () => {
  const middleware = sagaMiddleware()
  createStore(() => ({}), {}, applyMiddleware(middleware))
  const fn = () => null

  function* genFn() {
    const task = yield io.fork(() => io.call(fn))
    return task.toPromise()
  }

  return middleware
    .run(genFn)
    .toPromise()
    .then(actual => {
      expect(actual).toEqual(io.call(fn))
    })
})
test("should not interpret returned effect. yield fork(takeEvery, 'pattern', fn)", () => {
  const middleware = sagaMiddleware()
  createStore(() => ({}), {}, applyMiddleware(middleware))
  const fn = () => null

  function* genFn() {
    const task = yield io.fork(io.takeEvery, 'pattern', fn)
    return task.toPromise()
  }

  return middleware
    .run(genFn)
    .toPromise()
    .then(actual => {
      expect(actual).toEqual(io.takeEvery('pattern', fn))
    })
})

test('should interpret returned promise. fork(() => promise)', () => {
  const middleware = sagaMiddleware()
  createStore(() => ({}), {}, applyMiddleware(middleware))

  function* genFn() {
    const task = yield io.fork(() => Promise.resolve('a'))
    return task.toPromise()
  }

  return middleware
    .run(genFn)
    .toPromise()
    .then(actual => {
      expect(actual).toEqual('a')
    })
})
test('should interpret returned iterator. fork(() => iterator)', () => {
  const middleware = sagaMiddleware()
  createStore(() => ({}), {}, applyMiddleware(middleware))

  function* genFn() {
    const task = yield io.fork(function*() {
      yield 1
      return 'b'
    })
    return task.toPromise()
  }

  return middleware
    .run(genFn)
    .toPromise()
    .then(actual => {
      expect(actual).toEqual('b')
    })
})

@@ -558,24 +558,25 @@
 )%0A    %7D)%0A%7D)%0A
+%0A
 test(%22should
@@ -1437,16 +1437,472 @@
   %7D)%0A%7D)%0A
+%0Atest('should handle promise that resolves undefined properly. fork(() =%3E Promise.resolve(undefined))', () =%3E %7B%0A  const middleware = sagaMiddleware()%0A  createStore(() =%3E (%7B%7D), %7B%7D, applyMiddleware(middleware))%0A%0A  function* genFn() %7B%0A    const task = yield io.fork(() =%3E Promise.resolve(undefined))%0A    return task.toPromise()%0A  %7D%0A%0A  return middleware%0A    .run(genFn)%0A    .toPromise()%0A    .then(actual =%3E %7B%0A      expect(actual).toEqual(undefined)%0A    %7D)%0A%7D)%0A%0A
 test('sh

Add a test case that checks whether `fork` properly handle promises that resolves undefined