@@ -3,13 +3,13 @@ import TestUtils from 'react-dom/test-utils';
33import PureRenderMixin from 'react-addons-pure-render-mixin' ;
44import sinon from 'sinon' ;
55
6- import Formsy , { withFormsy , Wrapper } from './..' ;
6+ import Formsy , { withFormsy } from './..' ;
77import TestInput , { InputFactory } from './utils/TestInput' ;
88import immediate from './utils/immediate' ;
99
1010export default {
1111
12- 'should return passed and setValue() value when using getValue ()' : function ( test ) {
12+ 'should pass down correct value prop after using setValue ()' : function ( test ) {
1313
1414 const form = TestUtils . renderIntoDocument (
1515 < Formsy >
@@ -33,34 +33,7 @@ export default {
3333 this . props . setValue ( event . target . value , false ) ;
3434 }
3535 render ( ) {
36- return < input type = "text" value = { this . props . getValue ( ) } onChange = { this . updateValue } /> ;
37- }
38- } )
39- const form = TestUtils . renderIntoDocument (
40- < Formsy >
41- < Input name = "foo" value = "foo" innerRef = "comp" />
42- </ Formsy >
43- ) ;
44- const inputComponent = TestUtils . findRenderedComponentWithType ( form , Input ) ;
45- const setStateSpy = sinon . spy ( inputComponent , 'setState' ) ;
46- const inputElement = TestUtils . findRenderedDOMComponentWithTag ( form , 'INPUT' ) ;
47-
48- test . equal ( setStateSpy . called , false ) ;
49- TestUtils . Simulate . change ( inputElement , { target : { value : 'foobar' } } ) ;
50- test . equal ( setStateSpy . calledOnce , true ) ;
51- test . equal ( setStateSpy . calledWithExactly ( { value : 'foobar' } ) , true ) ;
52- test . done ( ) ;
53-
54- } ,
55-
56- 'Wrapper: should only set the value and not validate when calling setValue(val, false)' : function ( test ) {
57-
58- const Input = Wrapper ( class TestInput extends React . Component {
59- updateValue = ( event ) => {
60- this . props . setValue ( event . target . value , false ) ;
61- }
62- render ( ) {
63- return < input type = "text" value = { this . props . getValue ( ) } onChange = { this . updateValue } /> ;
36+ return < input type = "text" value = { this . props . value } onChange = { this . updateValue } /> ;
6437 }
6538 } )
6639 const form = TestUtils . renderIntoDocument (
@@ -105,10 +78,10 @@ export default {
10578
10679 'should return error message passed when calling getErrorMessage()' : function ( test ) {
10780
108- let getErrorMessage = null ;
81+ let errorMessage = null ;
10982 const Input = InputFactory ( {
11083 componentDidMount : function ( ) {
111- getErrorMessage = this . props . getErrorMessage ;
84+ errorMessage = this . props . errorMessage ;
11285 }
11386 } ) ;
11487 TestUtils . renderIntoDocument (
@@ -117,7 +90,7 @@ export default {
11790 </ Formsy >
11891 ) ;
11992
120- test . equal ( getErrorMessage ( ) , 'Has to be email' ) ;
93+ test . equal ( errorMessage , 'Has to be email' ) ;
12194
12295 test . done ( ) ;
12396
@@ -127,8 +100,8 @@ export default {
127100
128101 let isValid = null ;
129102 const Input = InputFactory ( {
130- componentDidMount : function ( ) {
131- isValid = this . props . isValid ;
103+ componentWillReceiveProps : function ( nextProps ) {
104+ isValid = nextProps . isValid ;
132105 }
133106 } ) ;
134107 const form = TestUtils . renderIntoDocument (
@@ -137,10 +110,10 @@ export default {
137110 </ Formsy >
138111 ) ;
139112
140- test . equal ( isValid ( ) , false ) ;
113+ test . equal ( isValid , false ) ;
141114 const input = TestUtils . findRenderedDOMComponentWithTag ( form , 'INPUT' ) ;
142115 TestUtils . Simulate . change ( input , { target :
{ value :
'[email protected] ' } } ) ; 143- test . equal ( isValid ( ) , true ) ;
116+ test . equal ( isValid , true ) ;
144117
145118 test . done ( ) ;
146119
@@ -162,9 +135,9 @@ export default {
162135 </ Formsy >
163136 ) ;
164137
165- test . equal ( isRequireds [ 0 ] ( ) , false ) ;
166- test . equal ( isRequireds [ 1 ] ( ) , true ) ;
167- test . equal ( isRequireds [ 2 ] ( ) , true ) ;
138+ test . equal ( isRequireds [ 0 ] , false ) ;
139+ test . equal ( isRequireds [ 1 ] , true ) ;
140+ test . equal ( isRequireds [ 2 ] , true ) ;
168141
169142 test . done ( ) ;
170143
@@ -186,9 +159,9 @@ export default {
186159 </ Formsy >
187160 ) ;
188161
189- test . equal ( showRequireds [ 0 ] ( ) , false ) ;
190- test . equal ( showRequireds [ 1 ] ( ) , true ) ;
191- test . equal ( showRequireds [ 2 ] ( ) , false ) ;
162+ test . equal ( showRequireds [ 0 ] , false ) ;
163+ test . equal ( showRequireds [ 1 ] , true ) ;
164+ test . equal ( showRequireds [ 2 ] , false ) ;
192165
193166 test . done ( ) ;
194167
@@ -198,8 +171,8 @@ export default {
198171
199172 let isPristine = null ;
200173 const Input = InputFactory ( {
201- componentDidMount : function ( ) {
202- isPristine = this . props . isPristine ;
174+ componentWillReceiveProps : function ( nextProps ) {
175+ isPristine = nextProps . isPristine ;
203176 }
204177 } ) ;
205178 const form = TestUtils . renderIntoDocument (
@@ -208,10 +181,10 @@ export default {
208181 </ Formsy >
209182 ) ;
210183
211- test . equal ( isPristine ( ) , true ) ;
184+ test . equal ( isPristine , true ) ;
212185 const input = TestUtils . findRenderedDOMComponentWithTag ( form , 'INPUT' ) ;
213186 TestUtils . Simulate . change ( input , { target : { value : 'foo' } } ) ;
214- test . equal ( isPristine ( ) , false ) ;
187+ test . equal ( isPristine , false ) ;
215188
216189 test . done ( ) ;
217190
@@ -618,7 +591,7 @@ export default {
618591 shouldComponentUpdate : function ( ) { return false } ,
619592 render : function ( ) {
620593 renderSpy ( ) ;
621- return < input type = { this . props . type } value = { this . props . getValue ( ) } onChange = { this . updateValue } /> ;
594+ return < input type = { this . props . type } value = { this . props . value } onChange = { this . updateValue } /> ;
622595 }
623596 } ) ;
624597
@@ -637,21 +610,10 @@ export default {
637610 'binds all necessary methods' : function ( test ) {
638611 const onInputRef = input => {
639612 [
640- 'getErrorMessage' ,
641- 'getErrorMessages' ,
642- 'getValue' ,
643- 'hasValue' ,
644- 'isFormDisabled' ,
645- 'isValid' ,
646- 'isPristine' ,
647- 'isFormSubmitted' ,
648- 'isRequired' ,
649613 'isValidValue' ,
650614 'resetValue' ,
651615 'setValidations' ,
652616 'setValue' ,
653- 'showRequired' ,
654- 'showError' ,
655617 ] . forEach ( fnName => {
656618 const fn = input [ fnName ] ;
657619 try {
0 commit comments