Skip to content

Instantly share code, notes, and snippets.

@johnmarinelli
Last active September 5, 2018 18:14
Show Gist options
  • Save johnmarinelli/b8b80676a275d2d89044a2aaf7bbbea0 to your computer and use it in GitHub Desktop.
Save johnmarinelli/b8b80676a275d2d89044a2aaf7bbbea0 to your computer and use it in GitHub Desktop.
redux-saga call() not working?
import { put, call, takeEvery } from 'redux-saga/effects'
import * as Actions from '@actions/Artsy'
export function* fetchData(client, artworkId) {
yield call(Actions.artsyFetchStart)
try {
const artwork = yield call(client.getData, { id: artworkId }) // this returns undefined
yield call(Actions.artsyFetchSuccess)
yield call(Actions.recieveArtwork, artwork)
return artwork
} catch (error) {
yield call(Actions.artsyFetchFailure)
}
}
export function* watchFetchArtwork() {
yield takeEvery(Actions.ARTSY_FETCH_ARTWORK, fetchArtwork)
}
import { fetchData } from './saga'
describe('Saga', () => {
const mockClient = {
getData: ({ id }) =>
new Promise(res => {
res({ id })
return { id }
}),
}
describe('fetchData', () => {
it('should call getData', () => {
const gen = fetchData(mockClient, 1)
expect(gen.next().value).toEqual(call(artsyFetchStart)) // this works
expect(gen.next().value).toEqual(call(mockClient.getData, { id: 1 })) // this works
expect(gen.next().value).toEqual(call(artsyFetchSuccess)) // this works
expect(gen.next().value).toEqual(call(recieveArtwork, { id: 1 })) // this fails, says argument is called with `undefined`
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment