Skip to content

Instantly share code, notes, and snippets.

@mcgrue
Created February 24, 2016 05:56
Show Gist options
  • Select an option

  • Save mcgrue/58068a80f1da4087cc10 to your computer and use it in GitHub Desktop.

Select an option

Save mcgrue/58068a80f1da4087cc10 to your computer and use it in GitHub Desktop.
it.only('works', function (){
const resultFn = fetchPosts( 'hot-tacos' );
expect(typeof resultFn).toEqual('function');
const dispatchStack = [];
const fakeDispatchFn = (dispatched) => {
dispatchStack.push(dispatched);
};
const fakeRes = {
json : () => { return getFakeRedditResponse(); }
};
expect(dispatchStack.length).toEqual(0);
const fakePromises = resultFn(fakeDispatchFn);
const callstack = fakePromises.callstack;
expect(dispatchStack.length).toEqual(1);
expect(callstack.length).toEqual(3);
expect(callstack[0]).toEqual("http://www.reddit.com/r/hot-tacos.json");
const return1 = callstack[1](fakeRes);
expect(return1).toEqual( getFakeRedditResponse() );
expect(dispatchStack.length).toEqual(1);
const return2 = callstack[2]( getFakeRedditResponse() );
expect(dispatchStack.length).toEqual(2);
console.log(dispatchStack);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment