Created
June 1, 2017 19:59
-
-
Save nikfrank/2f3ef67825511e4ee61698e1e4e790b8 to your computer and use it in GitHub Desktop.
Promise flow utilities for tahini testing
This file contains 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
// this does our redux flow backwardsification for us | |
// subscribe -> resolve next state; run trigger function | |
export const getNextState = (store, fn = ()=>0) => (...args)=> ( | |
new Promise((s, j)=>{ | |
const f = store.subscribe(()=>{ | |
f(); | |
s(store.getState()); | |
}); | |
fn(...args); | |
}) ); | |
// saves us a few functional programming points | |
export const toJS = state => state.toJS(); | |
// turns expectation errors into rejected promises for jest to report | |
// fn here will be our expectation block | |
export const rejectify = fn => state => { | |
try{ | |
fn(state); | |
return Promise.resolve(); | |
} catch(e) { | |
return Promise.reject(e); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment