-
-
Save prashantagarwal/384dbe937b5716bd16e91bf90ccb336d to your computer and use it in GitHub Desktop.
If all you have is a hammer, everything looks like a <Nail />
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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