Skip to content

Instantly share code, notes, and snippets.

@nikfrank
Last active June 1, 2017 20:06
Show Gist options
  • Save nikfrank/225bc6d2c97fd0e06b251050cfbc3bdf to your computer and use it in GitHub Desktop.
Save nikfrank/225bc6d2c97fd0e06b251050cfbc3bdf to your computer and use it in GitHub Desktop.
React async user scenario test
import React from 'react';
import { mount } from 'enzyme';
import {
// tahini application dep
bootStores,
connectDeviceFactory,
networkMiddleware,
// testing utils
getNextState,
toJS,
rejectify,
} from 'tahini';
import Pegging from './Pegging';
import Card from '../pure/Card';
import networkHandlers from '../network/';
it('only plays one card when multiclickd', () => {
// set up redux store and connect a device component to it
const stores = bootStores( [ networkMiddleware(networkHandlers) ] );
const { getDevice } = connectDeviceFactory( stores );
const { appStore } = stores;
const handInitState = Pegging.initState.merge({
hands: [
[
{ rank:11, suit:0 },
{ rank:11, suit:1 },
{ rank:11, suit:2 },
{ rank:11, suit:3 },
],
[
{ rank:12, suit:0 },
{ rank:12, suit:1 },
{ rank:12, suit:2 },
{ rank:12, suit:3 },
],
],
nextToPlay: 1,
});
const dataPath = [];
const PeggingDevice = getDevice(Pegging, dataPath, handInitState);
// p for comPonent. which is totally obvious if you're rainman.
const p = mount(
<PeggingDevice />
);
return Promise.resolve()
.then( ()=> p.find(Card) )
.then( getNextState(
appStore,
cards => {
cards.last().simulate('click');
cards.first().simulate('click');
}
)).then(toJS)
.then( rejectify( state => {
expect( state.played ).toHaveLength( 1 );
expect( state.hands[0] ).toHaveLength( 4 );
expect( state.hands[1] ).toHaveLength( 3 );
}) );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment