Skip to content

Instantly share code, notes, and snippets.

@prashantagarwal
Forked from MicheleBertoli/decribe.js
Created September 20, 2016 07:30
Show Gist options
  • Select an option

  • Save prashantagarwal/384dbe937b5716bd16e91bf90ccb336d to your computer and use it in GitHub Desktop.

Select an option

Save prashantagarwal/384dbe937b5716bd16e91bf90ccb336d to your computer and use it in GitHub Desktop.

Revisions

  1. @MicheleBertoli MicheleBertoli created this gist Sep 17, 2016.
    18 changes: 18 additions & 0 deletions decribe.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    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
    34 changes: 34 additions & 0 deletions it.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    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
    18 changes: 18 additions & 0 deletions test.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    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