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
function Todo(props) { | |
const { Delete, name, onDelete } = props; | |
return <div> | |
<span>{name}</span> | |
<Delete onSubmit={onDelete}>Delete</Delete> | |
</div>; | |
} |
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
it('should delete the todo when clicking on the delete button', function() { | |
const deleteTodo = sinon.spy(); | |
render(<Todo name=”buy milk” onDelete={deleteTodo} />); | |
Simulate.click($(‘.delete’)[0]); | |
expect(deleteTodo).to.have.been.called; | |
}); |
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
function inject(deps, Component) { | |
return class Injector extends React.Component { | |
render() { | |
return <Component {...deps} {...this.props} />; | |
} | |
}; | |
} | |
const SafeTodo = inject(Todo, { DeleteTodo: ConfirmButton }); | |
render(<TodoList Todo={SafeTodo} />); |
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
function createSpy() { | |
const _renderSpy = sinon.spy(); | |
return class Spy extends Component { | |
static get lastProps() { | |
return _renderSpy.args[_renderSpy.callCount - 1][0]; | |
} | |
render() { | |
_renderSpy(this.props); |
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
function Todo(props) { | |
return <div> | |
<span>{props.name}</span> | |
<button onClick={props.onDelete}>Delete</button> | |
</div>; | |
} |
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
function Todo(props) { | |
return <div> | |
<span>{props.name}</span> | |
</div>; | |
} |
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
it('should display the name of the todo', function() { | |
render(<Todo name="buy milk" />); | |
expect($('.todo').text()).to.equal('buy milk'); | |
}); |