Skip to content

Instantly share code, notes, and snippets.

@wolverineks
Created November 29, 2018 15:20
Show Gist options
  • Save wolverineks/f77f7fca2dc3537a82221464186566ad to your computer and use it in GitHub Desktop.
Save wolverineks/f77f7fca2dc3537a82221464186566ad to your computer and use it in GitHub Desktop.
Experiment with using JSX to write tests
// @flow
/* globals describe it expect */
import Renderer from 'react-test-renderer'
/** @jsx convert */
const convert = (component, props, children) => {
const args = { ...props, children }
return component(args)
}
export const Describe = ({ unit, children }: { children: any, unit: string }) => {
return describe(unit, children)
}
export const It = ({ description, expect }: { description: string, expect: Function }) => {
return () => it(description, expect)
}
const foo = (value = 123) => value
Renderer.create(
<Describe unit={'foo'}>
<It
description={'should return default value'}
expect={() => {
const expected = 123
const actual = foo()
expect(actual).toEqual(expected)
}}
/>
</Describe>
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment