Skip to content

Commit

Permalink
test(form): Element's sCU is called with correct value (formsy#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben Costa authored and hashwin committed Jun 12, 2019
1 parent 1473a94 commit b2b0eaa
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/Element-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,38 @@ export default {

},

'input should call shouldComponentUpdate with correct value': function (test) {

var renderSpy = sinon.spy();

const Input = InputFactory({
shouldComponentUpdate: function(prevProps) {
return prevProps.value !== this.props.value
},
render: function() {
renderSpy();
return <input type={this.props.type} value={this.props.value} onChange={this.updateValue}/>;
}
});

const form = TestUtils.renderIntoDocument(
<Formsy>
<Input name="foo" value="foo"/>
</Formsy>
);

const input = TestUtils.findRenderedDOMComponentWithTag(form, 'INPUT');

test.equal(renderSpy.calledOnce, true);

TestUtils.Simulate.change(input, {target: {value: 'fooz'}});
test.equal(input.value, 'fooz');
test.equal(renderSpy.calledTwice, true);

test.done();

},

'binds all necessary methods': function (test) {
const onInputRef = input => {
[
Expand Down

0 comments on commit b2b0eaa

Please sign in to comment.