/** @jest-environment node */
import withRedux from 'next-redux-wrapper'
import withReduxSaga from '..'
import AsyncGetInitialProps from './components/async-get-initial-props'
import ClassComponent from './components/class-component'
import FunctionalComponent from './components/functional-component'
import SyncGetInitialProps from './components/sync-get-initial-props'
import configureStore from './store/configure-store'
import createSnapshot from './utils/create-snapshot'
import getInitialProps from './utils/get-initial-props'
import {STATIC_PROP_TEXT, SYNC_REDUX_PROP_TEXT} from './constants'

test('Wrapped component passes along React props', () => {
  const WrappedComponent = withRedux(configureStore)(
    withReduxSaga(FunctionalComponent),
  )

  createSnapshot(WrappedComponent)
})

test('Wrapped component skips getInitialProps when it does not exist', async () => {
  const WrappedComponent = withRedux(configureStore)(
    withReduxSaga(ClassComponent),
  )

  const props = await getInitialProps(WrappedComponent)
  expect(props.isServer).toBeTruthy()

  createSnapshot(WrappedComponent, props)
})

test('Wrapped component awaits synchronous getInitialProps', async () => {
  const WrappedComponent = withRedux(configureStore)(
    withReduxSaga(SyncGetInitialProps),
  )

  const props = await getInitialProps(WrappedComponent)
  expect(props.isServer).toBeTruthy()
  expect(props.initialState).toEqual({syncReduxProp: SYNC_REDUX_PROP_TEXT})
  expect(props.initialProps).toEqual({staticProp: STATIC_PROP_TEXT})

  createSnapshot(WrappedComponent, props)
})

test('Wrapped component awaits asynchronous getInitialProps', async () => {
  const WrappedComponent = withRedux(configureStore)(
    withReduxSaga(AsyncGetInitialProps),
  )

  const props = await getInitialProps(WrappedComponent)
  expect(props.isServer).toBeTruthy()
  expect(props.initialState).toEqual({syncReduxProp: SYNC_REDUX_PROP_TEXT})
  expect(props.initialProps).toEqual({staticProp: STATIC_PROP_TEXT})

  createSnapshot(WrappedComponent, props)
})

@@ -535,16 +535,49 @@
 import %7B
+%0A  ASYNC_REDUX_SAGA_PROP_TEXT,%0A  
 STATIC_P
@@ -585,16 +585,18 @@
 OP_TEXT,
+%0A 
  SYNC_RE
@@ -608,16 +608,18 @@
 ROP_TEXT
+,%0A
 %7D from '
@@ -1909,32 +1909,37 @@
 State).toEqual(%7B
+%0A    
 syncReduxProp: S
@@ -1949,32 +1949,88 @@
 _REDUX_PROP_TEXT
+,%0A    asyncReduxSagaProp: ASYNC_REDUX_SAGA_PROP_TEXT,%0A  
 %7D)%0A  expect(prop

Fix failing test, the result looks much more correct now