Skip to content

Instantly share code, notes, and snippets.

@nikfrank
Created June 1, 2017 19:59
Show Gist options
  • Save nikfrank/2f3ef67825511e4ee61698e1e4e790b8 to your computer and use it in GitHub Desktop.
Save nikfrank/2f3ef67825511e4ee61698e1e4e790b8 to your computer and use it in GitHub Desktop.
Promise flow utilities for tahini testing
// 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