Skip to content

Instantly share code, notes, and snippets.

@faceyspacey
Last active March 28, 2019 10:38
Show Gist options
  • Save faceyspacey/91f9faa2ff64a50c11be83be83830d21 to your computer and use it in GitHub Desktop.
Save faceyspacey/91f9faa2ff64a50c11be83be83830d21 to your computer and use it in GitHub Desktop.
Respond Framework support for Statecharts
import { testGenerator } from 'respond-framework/test'
const routes = {
LOGIN: '/login',
SIGNUP: '/signup',
POST: '/post/:slug',
HOME: {
path: '/',
next: {
LOGIN: request => !!request.getState().cookies.existingUser,
SIGNUP: request => !request.getState().cookies.existingUser,
POST: {
cond: request => !!request.getState().loggedIn,
target: request => request.getState().posts.map(post => ({
type: 'POST',
params: { slug: post.slug }
})),
fallback: 'LOGIN'
}
}
}
}
describe('generated tests', async () => {
const options = {
initialState: {
posts: [
{ slug: '/respond-rocks' },
{ slug: '/thunk-life' }
]
}
}
await testGenerator(routes, options)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment