Last active
August 29, 2015 14:10
-
-
Save jstejada/904b94e34f352d5933fe to your computer and use it in GitHub Desktop.
Testing handlers for events with TestUtils.Simulate failing
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
React = require 'react/addons' | |
TestUtils = React.addons.TestUtils | |
# Component | |
Comp = React.createClass( | |
handleSubmit: (e)-> | |
@props.handleSubmit() | |
handleInputChange: (e)-> | |
render: -> | |
React.DOM.form onSubmit: @handleSubmit, | |
React.DOM.input type: "text", onChange: @handleInputChange | |
) | |
# Test | |
ddescribe "Comp", -> | |
beforeEach -> | |
@submitHandler = jasmine.createSpy "submitHandler" | |
@comp = TestUtils.renderIntoDocument React.createFactory(Comp)(handleSubmit: @submitHandler) | |
it 'assigns callbacks correctly', -> | |
form = TestUtils.findRenderedDOMComponentWithTag @comp, "form" | |
input = TestUtils.findRenderedDOMComponentWithTag @comp, "input" | |
expect(form.props.onSubmit).toEqual @comp.handleSubmit # SUCCEEDS | |
expect(input.props.onChange).toEqual @comp.handleInputChange # FAILS | |
it 'calls handleSubmit when form submitted', -> | |
spyOn(@comp, "handleSubmit").and.callThrough() | |
form = TestUtils.findRenderedDOMComponentWithTag @comp, "form" | |
TestUtils.Simulate.submit form.getDOMNode() | |
expect(@submitHandler).toHaveBeenCalled() # SUCCEEDS | |
expect(@comp.handleSubmit).toHaveBeenCalled() # FAILS | |
it 'calls handleInputChange when input changes', -> | |
spyOn(@comp, "handleInputChange").and.callThrough() | |
input = TestUtils.findRenderedDOMComponentWithTag @comp, "input" | |
TestUtils.Simulate.change input.getDOMNode() | |
expect(@comp.handleInputChange).toHaveBeenCalled() # FAILS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment