Created
November 29, 2018 15:20
-
-
Save wolverineks/f77f7fca2dc3537a82221464186566ad to your computer and use it in GitHub Desktop.
Experiment with using JSX to write tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @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