Skip to content

Instantly share code, notes, and snippets.

@nikfrank
nikfrank / peg2.test.js
Last active June 1, 2017 20:19
React user scenario with multiple events
import pegScore from '../util/pegScore';
it('disallows stack tipping', () => {
// 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({
@nikfrank
nikfrank / testing-util.js
Created June 1, 2017 19:59
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());
});
@nikfrank
nikfrank / add-then-reset.test.js
Last active June 1, 2017 20:35
React (crazy straw ugly flow) async user scenario test
it('adds a todo, then resets the device', (done) => {
// ... set up component and stores ...
// we're going to add a todo, then reset to the initState
expect( reduxStore.getState().get('todos').size )
.toEqual( TodoList.initState.get('todos').size );
// flow is backwards for async ops below
const clickResetAndCheck = ()=>{
@nikfrank
nikfrank / reset.test.js
Last active June 1, 2017 20:34
React ugly async user scenario
it('can reset a TodoList', (done)=>{
// .. set up component and store ...
const unsubscribe = reduxStore.subscribe(()=>{
expect( reduxStore.getState().get('todos').size )
.toEqual( TodoList.initState.get('todos').size );
unsubscribe();
done();
});
@nikfrank
nikfrank / peg.test.js
Last active June 1, 2017 20:06
React async user scenario test
import React from 'react';
import { mount } from 'enzyme';
import {
// tahini application dep
bootStores,
connectDeviceFactory,
networkMiddleware,