Skip to content

Instantly share code, notes, and snippets.

@MicheleBertoli
Created September 17, 2016 19:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MicheleBertoli/c29ab4d5f45d1292bb1c1153be56a81f to your computer and use it in GitHub Desktop.
Save MicheleBertoli/c29ab4d5f45d1292bb1c1153be56a81f to your computer and use it in GitHub Desktop.
If all you have is a hammer, everything looks like a <Nail />
import React, { PropTypes } from 'react'
const Describe = ({ title, children }) => (
<div>
<h1>{title}</h1>
<ul>{children}</ul>
</div>
)
Describe.propTypes = {
title: PropTypes.string,
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.element),
PropTypes.element,
]),
}
export default Describe
import React, { Component, PropTypes } from 'react'
class It extends Component {
constructor(props) {
super(props)
this.assert = this.assert.bind(this)
}
assert(condition) {
return (
<div style={{ color: condition ? 'green' : 'red' }}>
{this.props.title} {condition ? '😻' : '😿'}
</div>
)
}
render() {
return (
<li>
{this.props.children(this.assert)}
</li>
)
}
}
It.propTypes = {
title: PropTypes.string,
children: PropTypes.func,
}
export default It
import React from 'react'
import Describe from './describe'
import It from './it'
const add = (a, b) => a + b
const Test = () => (
<Describe title="add()">
<It title="adds two numbers">
{assert => assert(add(2, 3) === 5)}
</It>
<It title="doesn't add the third number">
{assert => assert(add(2, 3, 5) === add(2, 3))}
</It>
</Describe>
)
export default Test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment