Skip to content

Instantly share code, notes, and snippets.

@skellock
Created June 27, 2016 12:56
Show Gist options
  • Save skellock/2decd358f3b48e06ff514e807be2484d to your computer and use it in GitHub Desktop.
Save skellock/2decd358f3b48e06ff514e807be2484d to your computer and use it in GitHub Desktop.
import test from 'ava'
import saga, { acquireDataFromSomewhere } from '../TimeToShineSaga'
import { put, call, select } from 'redux-saga/effects'
test('the saga works', t => {
// grab the saga (generator function) to test
const gen = saga()
// a sugary helper to clean up our assertions below
const step = (mockLastYield) => gen.next(mockLastYield).value
// fake data to inject
const mockState = { counter: { value: 1234 } }
const currentCounterValue = mockState.counter.value
const mockData = 'Fakey McMockerson'
// test the 4 steps of our saga
t.deepEqual(step(), put({ type: 'INCREMENT' }))
t.deepEqual(step(), select())
t.deepEqual(
step(mockState),
call(acquireDataFromSomewhere, currentCounterValue)
)
t.deepEqual(
step(mockData),
put({type: 'SAVE_DATA', randomPieceOfData: mockData})
)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment