Created
June 27, 2016 12:56
-
-
Save skellock/2decd358f3b48e06ff514e807be2484d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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