diff --git a/API.md b/API.md
index 42150562..0de1bec1 100644
--- a/API.md
+++ b/API.md
@@ -52,7 +52,7 @@ Sets a class name on the form itself.
#### mapping
```jsx
-var MyForm = React.createClass({
+var MyForm = createReactClass({
mapInputs: function (inputs) {
return {
'field1': inputs.foo,
@@ -78,7 +78,7 @@ Use mapping to change the data structure of your input elements. This structure
You can manually pass down errors to your form. In combination with `onChange` you are able to validate using an external validator.
```jsx
-var Form = React.createClass({
+var Form = createReactClass({
getInitialState: function () {
return {
validationErrors: {}
@@ -147,7 +147,7 @@ Triggers when form is submitted with an invalid state. The arguments are the sam
#### reset(values)
```jsx
-var MyForm = React.createClass({
+var MyForm = createReactClass({
resetForm: function () {
this.refs.form.reset();
},
@@ -164,7 +164,7 @@ Manually reset the form to its pristine state. You can also pass an object that
#### getModel()
```jsx
-var MyForm = React.createClass({
+var MyForm = createReactClass({
getMyData: function () {
alert(this.refs.form.getModel());
},
@@ -181,7 +181,7 @@ Manually get values from all registered components. Keys are name of input and v
#### updateInputsWithError(errors)
```jsx
-var MyForm = React.createClass({
+var MyForm = createReactClass({
someFunction: function () {
this.refs.form.updateInputsWithError({
email: 'This email is taken',
@@ -201,7 +201,7 @@ Manually invalidate the form by taking an object that maps to inputs. This is us
#### preventExternalInvalidation
```jsx
-var MyForm = React.createClass({
+var MyForm = createReactClass({
onSubmit: function (model, reset, invalidate) {
invalidate({
foo: 'Got some error'
@@ -293,7 +293,7 @@ Would be typical for a checkbox type of form element that must be checked, e.g.
#### getValue()
```jsx
-var MyInput = React.createClass({
+var MyInput = createReactClass({
mixins: [Formsy.Mixin],
render: function () {
return (
@@ -306,7 +306,7 @@ Gets the current value of the form input component.
#### setValue(value)
```jsx
-var MyInput = React.createClass({
+var MyInput = createReactClass({
mixins: [Formsy.Mixin],
changeValue: function (event) {
this.setValue(event.currentTarget.value);
@@ -322,7 +322,7 @@ Sets the value of your form input component. Notice that it does not have to be
#### resetValue()
```jsx
-var MyInput = React.createClass({
+var MyInput = createReactClass({
mixins: [Formsy.Mixin],
changeValue: function (event) {
this.setValue(event.currentTarget.value);
@@ -341,7 +341,7 @@ Resets to empty value. This will run a **setState()** on the component and do a
#### getErrorMessage()
```jsx
-var MyInput = React.createClass({
+var MyInput = createReactClass({
mixins: [Formsy.Mixin],
changeValue: function (event) {
this.setValue(event.currentTarget.value);
@@ -363,7 +363,7 @@ Will return the validation messages set if the form input component is invalid.
#### isValid()
```jsx
-var MyInput = React.createClass({
+var MyInput = createReactClass({
mixins: [Formsy.Mixin],
changeValue: function (event) {
this.setValue(event.currentTarget.value);
@@ -386,7 +386,7 @@ Returns the valid state of the form input component.
You can pre-verify a value against the passed validators to the form element.
```jsx
-var MyInput = React.createClass({
+var MyInput = createReactClass({
mixins: [Formsy.Mixin],
changeValue: function (event) {
if (this.isValidValue(event.target.value)) {
@@ -398,7 +398,7 @@ var MyInput = React.createClass({
}
});
-var MyForm = React.createClass({
+var MyForm = createReactClass({
render: function () {
return (
@@ -411,7 +411,7 @@ var MyForm = React.createClass({
#### isRequired()
```jsx
-var MyInput = React.createClass({
+var MyInput = createReactClass({
mixins: [Formsy.Mixin],
changeValue: function (event) {
this.setValue(event.currentTarget.value);
@@ -431,7 +431,7 @@ Returns true if the required property has been passed.
#### showRequired()
```jsx
-var MyInput = React.createClass({
+var MyInput = createReactClass({
mixins: [Formsy.Mixin],
changeValue: function (event) {
this.setValue(event.currentTarget.value);
@@ -451,7 +451,7 @@ Lets you check if the form input component should indicate if it is a required f
#### showError()
```jsx
-var MyInput = React.createClass({
+var MyInput = createReactClass({
mixins: [Formsy.Mixin],
changeValue: function (event) {
this.setValue(event.currentTarget.value);
@@ -471,7 +471,7 @@ Lets you check if the form input component should indicate if there is an error.
#### isPristine()
```jsx
-var MyInput = React.createClass({
+var MyInput = createReactClass({
mixins: [Formsy.Mixin],
changeValue: function (event) {
this.setValue(event.currentTarget.value);
@@ -492,7 +492,7 @@ By default all formsy input elements are pristine, which means they are not "tou
#### isFormDisabled()
```jsx
-var MyInput = React.createClass({
+var MyInput = createReactClass({
mixins: [Formsy.Mixin],
render: function () {
return (
@@ -509,7 +509,7 @@ You can now disable the form itself with a prop and use **isFormDisabled()** ins
#### isFormSubmitted()
```jsx
-var MyInput = React.createClass({
+var MyInput = createReactClass({
mixins: [Formsy.Mixin],
render: function () {
var error = this.isFormSubmitted() ? this.getErrorMessage() : null;
@@ -526,7 +526,7 @@ You can check if the form has been submitted.
#### validate
```jsx
-var MyInput = React.createClass({
+var MyInput = createReactClass({
mixins: [Formsy.Mixin],
changeValue: function (event) {
this.setValue(event.target.value);
@@ -550,7 +550,7 @@ You can create custom validation inside a form element. The validate method defi
#### formNoValidate
To avoid native validation behavior on inputs, use the React `formNoValidate` property.
```jsx
-var MyInput = React.createClass({
+var MyInput = createReactClass({
mixins: [Formsy.Mixin],
render: function () {
return (
@@ -584,7 +584,7 @@ export default HOC(MyInputHoc);
Use an `innerRef` prop to get a reference to your DOM node.
```jsx
-var MyForm = React.createClass({
+var MyForm = createReactClass({
componentDidMount() {
this.searchInput.focus()
},
diff --git a/README.md b/README.md
index 65cacd14..1d5bff0e 100644
--- a/README.md
+++ b/README.md
@@ -49,7 +49,7 @@ Complete API reference is available [here](/API.md).
```jsx
import Formsy from 'formsy-react';
- const MyAppForm = React.createClass({
+ const MyAppForm = createReactClass({
getInitialState() {
return {
canSubmit: false
@@ -85,7 +85,7 @@ This code results in a form with a submit button that will run the `submit` meth
```jsx
import Formsy from 'formsy-react';
- const MyOwnInput = React.createClass({
+ const MyOwnInput = createReactClass({
// Add the Formsy Mixin
mixins: [Formsy.Mixin],
diff --git a/examples/components/Input.js b/examples/components/Input.js
index fd668344..131a25bc 100644
--- a/examples/components/Input.js
+++ b/examples/components/Input.js
@@ -1,7 +1,7 @@
import React from 'react';
import Formsy from 'formsy-react';
-const MyInput = React.createClass({
+const MyInput = createReactClass({
// Add the Formsy Mixin
mixins: [Formsy.Mixin],
diff --git a/examples/components/MultiCheckboxSet.js b/examples/components/MultiCheckboxSet.js
index 1b4c9cc2..0019f578 100644
--- a/examples/components/MultiCheckboxSet.js
+++ b/examples/components/MultiCheckboxSet.js
@@ -10,7 +10,7 @@ function contains(container, item, cmp) {
return false;
}
-const MyRadioGroup = React.createClass({
+const MyRadioGroup = createReactClass({
mixins: [Formsy.Mixin],
getInitialState() {
return { value: [], cmp: (a, b) => a === b };
diff --git a/examples/components/RadioGroup.js b/examples/components/RadioGroup.js
index 985e620e..9c60a074 100644
--- a/examples/components/RadioGroup.js
+++ b/examples/components/RadioGroup.js
@@ -1,7 +1,7 @@
import React from 'react';
import Formsy from 'formsy-react';
-const MyRadioGroup = React.createClass({
+const MyRadioGroup = createReactClass({
mixins: [Formsy.Mixin],
componentDidMount() {
diff --git a/examples/components/Select.js b/examples/components/Select.js
index cf619be7..66a8b34e 100644
--- a/examples/components/Select.js
+++ b/examples/components/Select.js
@@ -1,7 +1,7 @@
import React from 'react';
import Formsy from 'formsy-react';
-const MySelect = React.createClass({
+const MySelect = createReactClass({
mixins: [Formsy.Mixin],
changeValue(event) {
diff --git a/examples/custom-validation/app.js b/examples/custom-validation/app.js
index 15f4e027..ebba41f3 100644
--- a/examples/custom-validation/app.js
+++ b/examples/custom-validation/app.js
@@ -29,7 +29,7 @@ Formsy.addValidationRule('isYearOfBirth', (values, value) => {
return value < currentYear && value > currentYear - 130;
});
-const App = React.createClass({
+const App = createReactClass({
submit(data) {
alert(JSON.stringify(data, null, 4));
},
@@ -44,7 +44,7 @@ const App = React.createClass({
}
});
-const DynamicInput = React.createClass({
+const DynamicInput = createReactClass({
mixins: [Formsy.Mixin],
getInitialState() {
return { validationType: 'time' };
@@ -79,7 +79,7 @@ const DynamicInput = React.createClass({
}
});
-const Validations = React.createClass({
+const Validations = createReactClass({
changeValidation(e) {
this.props.changeValidation(e.target.value);
},
diff --git a/examples/dynamic-form-fields/app.js b/examples/dynamic-form-fields/app.js
index 2159788a..cd572364 100644
--- a/examples/dynamic-form-fields/app.js
+++ b/examples/dynamic-form-fields/app.js
@@ -54,7 +54,7 @@ const Fields = props => {
);
};
-const App = React.createClass({
+const App = createReactClass({
getInitialState() {
return { fields: [], canSubmit: false };
},
diff --git a/examples/login/app.js b/examples/login/app.js
index dfa5de4f..cb422103 100644
--- a/examples/login/app.js
+++ b/examples/login/app.js
@@ -4,7 +4,7 @@ import { Form } from 'formsy-react';
import MyInput from './../components/Input';
-const App = React.createClass({
+const App = createReactClass({
getInitialState() {
return { canSubmit: false };
},
diff --git a/examples/reset-values/app.js b/examples/reset-values/app.js
index d5deb8f4..f5a85ca3 100644
--- a/examples/reset-values/app.js
+++ b/examples/reset-values/app.js
@@ -11,7 +11,7 @@ const user = {
hair: 'brown'
};
-const App = React.createClass({
+const App = createReactClass({
submit(data) {
alert(JSON.stringify(data, null, 4));
},
diff --git a/package.json b/package.json
index 225ce693..31d466b9 100644
--- a/package.json
+++ b/package.json
@@ -23,7 +23,9 @@
"react-component"
],
"dependencies": {
- "form-data-to-object": "^0.2.0"
+ "create-react-class": "^15.5.2",
+ "form-data-to-object": "^0.2.0",
+ "prop-types": "^15.5.7"
},
"devDependencies": {
"babel-cli": "^6.6.5",
@@ -33,15 +35,14 @@
"babel-preset-stage-2": "^6.5.0",
"jsdom": "^6.5.1",
"nodeunit": "^0.9.1",
- "react": "^15.0.0",
+ "react": "^15.5.4",
"react-addons-pure-render-mixin": "^15.0.0",
- "react-addons-test-utils": "^15.0.0",
- "react-dom": "^15.0.0",
+ "react-dom": "^15.5.4",
"sinon": "^1.17.3",
"webpack": "^1.12.14",
"webpack-dev-server": "^1.14.1"
},
"peerDependencies": {
- "react": "^0.14.0 || ^15.0.0"
+ "react": "^0.14.0 || ^15.5.0"
}
}
diff --git a/src/Decorator.js b/src/Decorator.js
index f9a4b35d..d6a4aae6 100644
--- a/src/Decorator.js
+++ b/src/Decorator.js
@@ -1,29 +1,9 @@
var React = global.React || require('react');
-var Mixin = require('./Mixin.js');
-module.exports = function () {
- return function (Component) {
- return React.createClass({
- mixins: [Mixin],
- render: function () {
- return React.createElement(Component, {
- setValidations: this.setValidations,
- setValue: this.setValue,
- resetValue: this.resetValue,
- getValue: this.getValue,
- hasValue: this.hasValue,
- getErrorMessage: this.getErrorMessage,
- getErrorMessages: this.getErrorMessages,
- isFormDisabled: this.isFormDisabled,
- isValid: this.isValid,
- isPristine: this.isPristine,
- isFormSubmitted: this.isFormSubmitted,
- isRequired: this.isRequired,
- showRequired: this.showRequired,
- showError: this.showError,
- isValidValue: this.isValidValue,
- ...this.props
- });
- }
- });
- };
-};
+
+import Mixin from './Mixin.js';
+
+export default () => (Component) => Mixin((props) => {
+ return (
+
+ )
+})
diff --git a/src/HOC.js b/src/HOC.js
index 849b69c5..4cf8a6e9 100644
--- a/src/HOC.js
+++ b/src/HOC.js
@@ -1,43 +1,22 @@
var React = global.React || require('react');
-var Mixin = require('./Mixin.js');
-module.exports = function (Component) {
- return React.createClass({
- displayName: 'Formsy(' + getDisplayName(Component) + ')',
- mixins: [Mixin],
- render: function () {
- const { innerRef } = this.props;
- const propsForElement = {
- setValidations: this.setValidations,
- setValue: this.setValue,
- resetValue: this.resetValue,
- getValue: this.getValue,
- hasValue: this.hasValue,
- getErrorMessage: this.getErrorMessage,
- getErrorMessages: this.getErrorMessages,
- isFormDisabled: this.isFormDisabled,
- isValid: this.isValid,
- isPristine: this.isPristine,
- isFormSubmitted: this.isFormSubmitted,
- isRequired: this.isRequired,
- showRequired: this.showRequired,
- showError: this.showError,
- isValidValue: this.isValidValue,
- ...this.props
- };
+import Mixin from './Mixin.js';
- if (innerRef) {
- propsForElement.ref = innerRef;
- }
- return React.createElement(Component, propsForElement);
- }
- });
-};
-
-function getDisplayName(Component) {
+const getDisplayName = (Component) => {
return (
Component.displayName ||
Component.name ||
(typeof Component === 'string' ? Component : 'Component')
);
}
+
+export default (Component) => Mixin(class extends React.Component {
+ displayName = `Formsy(${getDisplayName(Component)})`
+
+ render() {
+ const { innerRef } = this.props;
+ return (
+
+ )
+ }
+})
diff --git a/src/Mixin.js b/src/Mixin.js
index d615fc7a..3e6cbda3 100644
--- a/src/Mixin.js
+++ b/src/Mixin.js
@@ -1,8 +1,8 @@
-var utils = require('./utils.js');
var React = global.React || require('react');
+var PropTypes = require('prop-types');
+var utils = require('./utils.js');
-var convertValidationsToObject = function (validations) {
-
+const convertValidationsToObject = (validations) => {
if (typeof validations === 'string') {
return validations.split(/\,(?![^{\[]*[}\]])/g).reduce(function (validations, validation) {
@@ -30,37 +30,35 @@ var convertValidationsToObject = function (validations) {
return validations || {};
};
-module.exports = {
- getInitialState: function () {
- return {
- _value: this.props.value,
- _isRequired: false,
- _isValid: true,
- _isPristine: true,
- _pristineValue: this.props.value,
- _validationError: [],
- _externalError: null,
- _formSubmitted: false
- };
- },
- contextTypes: {
- formsy: React.PropTypes.object // What about required?
- },
- getDefaultProps: function () {
- return {
- validationError: '',
- validationErrors: {}
- };
- },
+export default (Component) => class extends React.Component {
+ state = {
+ _value: this.props.value,
+ _isRequired: false,
+ _isValid: true,
+ _isPristine: true,
+ _pristineValue: this.props.value,
+ _validationError: [],
+ _externalError: null,
+ _formSubmitted: false
+ }
- componentWillMount: function () {
- var configure = function () {
+ static defaultProps = {
+ validationError: '',
+ validationErrors: {}
+ }
+
+ static contextTypes = {
+ formsy: PropTypes.object // What about required?
+ }
+
+ componentWillMount() {
+ var configure = () => {
this.setValidations(this.props.validations, this.props.required);
// Pass a function instead?
this.context.formsy.attachToForm(this);
//this.props._attachToForm(this);
- }.bind(this);
+ };
if (!this.props.name) {
throw new Error('Form Input requires a name property when used');
@@ -78,16 +76,14 @@ module.exports = {
}
*/
configure();
- },
+ }
// We have to make the validate method is kept when new props are added
- componentWillReceiveProps: function (nextProps) {
+ componentWillReceiveProps(nextProps) {
this.setValidations(nextProps.validations, nextProps.required);
+ }
- },
-
- componentDidUpdate: function (prevProps) {
-
+ componentDidUpdate(prevProps) {
// If the value passed has changed, set it. If value is not passed it will
// internally update, and this will never run
if (!utils.isSame(this.props.value, prevProps.value)) {
@@ -98,77 +94,111 @@ module.exports = {
if (!utils.isSame(this.props.validations, prevProps.validations) || !utils.isSame(this.props.required, prevProps.required)) {
this.context.formsy.validate(this);
}
- },
+ }
// Detach it when component unmounts
- componentWillUnmount: function () {
+ componentWillUnmount() {
this.context.formsy.detachFromForm(this);
//this.props._detachFromForm(this);
- },
+ }
+
+ render() {
+ const props = {
+ setValidations: this.setValidations,
+ setValue: this.setValue,
+ resetValue: this.resetValue,
+ getValue: this.getValue,
+ hasValue: this.hasValue,
+ getErrorMessage: this.getErrorMessage,
+ getErrorMessages: this.getErrorMessages,
+ isFormDisabled: this.isFormDisabled,
+ isValid: this.isValid,
+ isPristine: this.isPristine,
+ isFormSubmitted: this.isFormSubmitted,
+ isRequired: this.isRequired,
+ showRequired: this.showRequired,
+ showError: this.showError,
+ isValidValue: this.isValidValue,
+ ...this.props
+ };
- setValidations: function (validations, required) {
+ return
+ }
+ setValidations = (validations, required) => {
// Add validations to the store itself as the props object can not be modified
this._validations = convertValidationsToObject(validations) || {};
this._requiredValidations = required === true ? {isDefaultRequiredValue: true} : convertValidationsToObject(required);
-
- },
+ }
// We validate after the value has been set
- setValue: function (value) {
+ setValue = (value) => {
this.setState({
_value: value,
_isPristine: false
- }, function () {
+ }, () => {
this.context.formsy.validate(this);
//this.props._validate(this);
- }.bind(this));
- },
- resetValue: function () {
+ });
+ }
+
+ resetValue = () => {
this.setState({
_value: this.state._pristineValue,
_isPristine: true
- }, function () {
+ }, () => {
this.context.formsy.validate(this);
//this.props._validate(this);
});
- },
- getValue: function () {
+ }
+
+ getValue = () => {
return this.state._value;
- },
- hasValue: function () {
+ }
+
+ hasValue = () => {
return this.state._value !== '';
- },
- getErrorMessage: function () {
+ }
+
+ getErrorMessage = () => {
var messages = this.getErrorMessages();
return messages.length ? messages[0] : null;
- },
- getErrorMessages: function () {
+ }
+
+ getErrorMessages = () => {
return !this.isValid() || this.showRequired() ? (this.state._externalError || this.state._validationError || []) : [];
- },
- isFormDisabled: function () {
+ }
+
+ isFormDisabled = () => {
return this.context.formsy.isFormDisabled();
//return this.props._isFormDisabled();
- },
- isValid: function () {
+ }
+
+ isValid = () => {
return this.state._isValid;
- },
- isPristine: function () {
+ }
+
+ isPristine = () => {
return this.state._isPristine;
- },
- isFormSubmitted: function () {
+ }
+
+ isFormSubmitted = () => {
return this.state._formSubmitted;
- },
- isRequired: function () {
+ }
+
+ isRequired = () => {
return !!this.props.required;
- },
- showRequired: function () {
+ }
+
+ showRequired = () => {
return this.state._isRequired;
- },
- showError: function () {
+ }
+
+ showError = () => {
return !this.showRequired() && !this.isValid();
- },
- isValidValue: function (value) {
+ }
+
+ isValidValue = (value) => {
return this.context.formsy.isValidValue.call(null, this, value);
//return this.props._isValidValue.call(null, this, value);
}
diff --git a/src/main.js b/src/main.js
index f7b5e8eb..0cfea130 100644
--- a/src/main.js
+++ b/src/main.js
@@ -1,17 +1,20 @@
var React = global.React || require('react');
-var Formsy = {};
-var validationRules = require('./validationRules.js');
-var formDataToObject = require('form-data-to-object');
-var utils = require('./utils.js');
-var Mixin = require('./Mixin.js');
-var HOC = require('./HOC.js');
-var Decorator = require('./Decorator.js');
-var options = {};
-var emptyArray = [];
-Formsy.Mixin = Mixin;
+import PropTypes from 'prop-types'
+import formDataToObject from 'form-data-to-object';
+import validationRules from './validationRules.js';
+import utils from './utils.js';
+import Mixin from './Mixin.js';
+import HOC from './HOC.js';
+import Decorator from './Decorator.js';
+
+let options = {};
+let emptyArray = [];
+let Formsy = {}
+
Formsy.HOC = HOC;
Formsy.Decorator = Decorator;
+Formsy.Mixin = Mixin;
Formsy.defaults = function (passedOptions) {
options = passedOptions;
@@ -21,34 +24,34 @@ Formsy.addValidationRule = function (name, func) {
validationRules[name] = func;
};
-Formsy.Form = React.createClass({
- displayName: 'Formsy',
- getInitialState: function () {
- return {
- isValid: true,
- isSubmitting: false,
- canChange: false
- };
- },
- getDefaultProps: function () {
- return {
- onSuccess: function () {},
- onError: function () {},
- onSubmit: function () {},
- onValidSubmit: function () {},
- onInvalidSubmit: function () {},
- onValid: function () {},
- onInvalid: function () {},
- onChange: function () {},
- validationErrors: null,
- preventExternalInvalidation: false
- };
- },
+class Form extends React.Component {
+ displayName = 'Formsy'
+
+ static childContextTypes = {
+ formsy: PropTypes.object
+ }
+
+ state = {
+ isValid: true,
+ isSubmitting: false,
+ canChange: false
+ }
+
+ static defaultProps = {
+ onSuccess: () => {},
+ onError: () => {},
+ onSubmit: () => {},
+ onValidSubmit: () => {},
+ onInvalidSubmit: () => {},
+ onValid: () => {},
+ onInvalid: () => {},
+ onChange: () => {},
+ validationErrors: null,
+ preventExternalInvalidation: false
+ }
- childContextTypes: {
- formsy: React.PropTypes.object
- },
- getChildContext: function () {
+
+ getChildContext() {
return {
formsy: {
attachToForm: this.attachToForm,
@@ -60,26 +63,25 @@ Formsy.Form = React.createClass({
}
}
}
- },
+ }
// Add a map to store the inputs of the form, a model to store
// the values of the form and register child inputs
- componentWillMount: function () {
+ componentWillMount() {
this.inputs = [];
- },
+ }
- componentDidMount: function () {
+ componentDidMount() {
this.validateForm();
- },
+ }
- componentWillUpdate: function () {
+ componentWillUpdate() {
// Keep a reference to input names before form updates,
// to check if inputs has changed after render
this.prevInputNames = this.inputs.map(component => component.props.name);
- },
-
- componentDidUpdate: function () {
+ }
+ componentDidUpdate() {
if (this.props.validationErrors && typeof this.props.validationErrors === 'object' && Object.keys(this.props.validationErrors).length > 0) {
this.setInputValidationErrors(this.props.validationErrors);
}
@@ -88,18 +90,16 @@ Formsy.Form = React.createClass({
if (utils.arraysDiffer(this.prevInputNames, newInputNames)) {
this.validateForm();
}
-
- },
+ }
// Allow resetting to specified data
- reset: function (data) {
+ reset = (data) => {
this.setFormPristine(true);
this.resetModel(data);
- },
+ }
// Update model, submit to url prop and send the model
- submit: function (event) {
-
+ submit = (event) => {
event && event.preventDefault();
// Trigger form as not pristine.
@@ -109,11 +109,9 @@ Formsy.Form = React.createClass({
var model = this.getModel();
this.props.onSubmit(model, this.resetModel, this.updateInputsWithError);
this.state.isValid ? this.props.onValidSubmit(model, this.resetModel, this.updateInputsWithError) : this.props.onInvalidSubmit(model, this.resetModel, this.updateInputsWithError);
+ }
- },
-
- mapModel: function (model) {
-
+ mapModel(model) {
if (this.props.mapping) {
return this.props.mapping(model)
} else {
@@ -130,15 +128,15 @@ Formsy.Form = React.createClass({
}, {}));
}
- },
+ }
- getModel: function () {
+ getModel() {
var currentValues = this.getCurrentValues();
return this.mapModel(currentValues);
- },
+ }
// Reset each key in the model to the original / initial / specified value
- resetModel: function (data) {
+ resetModel (data) {
this.inputs.forEach(component => {
var name = component.props.name;
if (data && data.hasOwnProperty(name)) {
@@ -148,9 +146,9 @@ Formsy.Form = React.createClass({
}
});
this.validateForm();
- },
+ }
- setInputValidationErrors: function (errors) {
+ setInputValidationErrors(errors) {
this.inputs.forEach(component => {
var name = component.props.name;
var args = [{
@@ -159,25 +157,25 @@ Formsy.Form = React.createClass({
}];
component.setState.apply(component, args);
});
- },
+ }
// Checks if the values have changed from their initial value
- isChanged: function() {
+ isChanged() {
return !utils.isSame(this.getPristineValues(), this.getCurrentValues());
- },
+ }
- getPristineValues: function() {
+ getPristineValues() {
return this.inputs.reduce((data, component) => {
var name = component.props.name;
data[name] = component.props.value;
return data;
}, {});
- },
+ }
// Go through errors from server and grab the components
// stored in the inputs map. Change their state to invalid
// and set the serverError message
- updateInputsWithError: function (errors) {
+ updateInputsWithError(errors) {
Object.keys(errors).forEach((name, index) => {
var component = utils.find(this.inputs, component => component.props.name === name);
if (!component) {
@@ -190,21 +188,21 @@ Formsy.Form = React.createClass({
}];
component.setState.apply(component, args);
});
- },
+ }
- isFormDisabled: function () {
+ isFormDisabled = () => {
return this.props.disabled;
- },
+ }
- getCurrentValues: function () {
+ getCurrentValues() {
return this.inputs.reduce((data, component) => {
var name = component.props.name;
data[name] = component.state._value;
return data;
}, {});
- },
+ }
- setFormPristine: function (isPristine) {
+ setFormPristine(isPristine) {
this.setState({
_formSubmitted: !isPristine
});
@@ -217,13 +215,12 @@ Formsy.Form = React.createClass({
_isPristine: isPristine
});
});
- },
+ }
// Use the binded values and the actual input value to
// validate the input and set its state. Then check the
// state of the form itself
- validate: function (component) {
-
+ validate = (component) => {
// Trigger onChange
if (this.state.canChange) {
this.props.onChange(this.getCurrentValues(), this.isChanged());
@@ -238,12 +235,10 @@ Formsy.Form = React.createClass({
_validationError: validation.error,
_externalError: null
}, this.validateForm);
-
- },
+ }
// Checks validation on current value or a passed value
- runValidation: function (component, value) {
-
+ runValidation(component, value) {
var currentValues = this.getCurrentValues();
var validationErrors = component.props.validationErrors;
var validationError = component.props.validationError;
@@ -293,11 +288,9 @@ Formsy.Form = React.createClass({
}.call(this))
};
+ }
- },
-
- runRules: function (value, currentValues, validations) {
-
+ runRules(value, currentValues, validations) {
var results = {
errors: [],
failed: [],
@@ -344,13 +337,11 @@ Formsy.Form = React.createClass({
}
return results;
-
- },
+ }
// Validate the form by going through all child input components
// and check their state
- validateForm: function () {
-
+ validateForm = () => {
// We need a callback as we are validating all inputs again. This will
// run when the last component has set its state
var onValidationComplete = function () {
@@ -392,27 +383,26 @@ Formsy.Form = React.createClass({
// If there are no inputs, set state where form is ready to trigger
// change event. New inputs might be added later
- if (!this.inputs.length && this.isMounted()) {
+ if (!this.inputs.length) {
this.setState({
canChange: true
});
}
- },
+ }
// Method put on each input component to register
// itself to the form
- attachToForm: function (component) {
-
+ attachToForm = (component) => {
if (this.inputs.indexOf(component) === -1) {
this.inputs.push(component);
}
this.validate(component);
- },
+ }
// Method put on each input component to unregister
// itself from the form
- detachFromForm: function (component) {
+ detachFromForm = (component) => {
var componentPos = this.inputs.indexOf(component);
if (componentPos !== -1) {
@@ -421,8 +411,9 @@ Formsy.Form = React.createClass({
}
this.validateForm();
- },
- render: function () {
+ }
+
+ render() {
var {
mapping,
validationErrors,
@@ -444,9 +435,10 @@ Formsy.Form = React.createClass({
{this.props.children}
);
-
}
-});
+};
+
+Formsy.Form = Form;
if (!global.exports && !global.module && (!global.define || !global.define.amd)) {
global.Formsy = Formsy;
diff --git a/tests/Element-spec.js b/tests/Element-spec.js
index 38b93acc..9b5a96e7 100644
--- a/tests/Element-spec.js
+++ b/tests/Element-spec.js
@@ -1,10 +1,9 @@
import React from 'react';
-import TestUtils from 'react-addons-test-utils';
-import PureRenderMixin from 'react-addons-pure-render-mixin';
+import TestUtils from 'react-dom/test-utils';
import sinon from 'sinon';
import Formsy from './..';
-import TestInput, { InputFactory } from './utils/TestInput';
+import TestInput from './utils/TestInput';
import immediate from './utils/immediate';
export default {
@@ -29,11 +28,12 @@ export default {
'should set back to pristine value when running reset': function (test) {
let reset = null;
- const Input = InputFactory({
+ const Input = class extends TestInput {
componentDidMount() {
reset = this.resetValue;
}
- });
+ };
+
const form = TestUtils.renderIntoDocument(
@@ -52,11 +52,12 @@ export default {
'should return error message passed when calling getErrorMessage()': function (test) {
let getErrorMessage = null;
- const Input = InputFactory({
+ const Input = class extends TestInput {
componentDidMount() {
getErrorMessage = this.getErrorMessage;
}
- });
+ };
+
TestUtils.renderIntoDocument(
@@ -72,11 +73,12 @@ export default {
'should return true or false when calling isValid() depending on valid state': function (test) {
let isValid = null;
- const Input = InputFactory({
+ const Input = class extends TestInput {
componentDidMount() {
isValid = this.isValid;
}
- });
+ };
+
const form = TestUtils.renderIntoDocument(
@@ -95,11 +97,12 @@ export default {
'should return true or false when calling isRequired() depending on passed required attribute': function (test) {
const isRequireds = [];
- const Input = InputFactory({
+ const Input = class extends TestInput {
componentDidMount() {
isRequireds.push(this.isRequired);
}
- });
+ };
+
TestUtils.renderIntoDocument(
@@ -119,11 +122,12 @@ export default {
'should return true or false when calling showRequired() depending on input being empty and required is passed, or not': function (test) {
const showRequireds = [];
- const Input = InputFactory({
+ const Input = class extends TestInput {
componentDidMount() {
showRequireds.push(this.showRequired);
}
- });
+ };
+
TestUtils.renderIntoDocument(
@@ -143,11 +147,11 @@ export default {
'should return true or false when calling isPristine() depending on input has been "touched" or not': function (test) {
let isPristine = null;
- const Input = InputFactory({
+ const Input = class extends TestInput{
componentDidMount() {
isPristine = this.isPristine;
}
- });
+ };
const form = TestUtils.renderIntoDocument(
@@ -164,16 +168,15 @@ export default {
},
'should allow an undefined value to be updated to a value': function (test) {
+ class TestForm extends React.Component {
+ state = {value: undefined};
- const TestForm = React.createClass({
- getInitialState() {
- return {value: undefined};
- },
- changeValue() {
+ changeValue = () => {
this.setState({
value: 'foo'
});
- },
+ };
+
render() {
return (
@@ -181,7 +184,8 @@ export default {
);
}
- });
+ }
+
const form = TestUtils.renderIntoDocument();
form.changeValue();
@@ -190,12 +194,10 @@ export default {
test.equal(input.value, 'foo');
test.done();
});
-
},
'should be able to test a values validity': function (test) {
-
- const TestForm = React.createClass({
+ class TestForm extends React.Component {
render() {
return (
@@ -203,19 +205,18 @@ export default {
);
}
- });
+ }
+
const form = TestUtils.renderIntoDocument();
const input = TestUtils.findRenderedComponentWithType(form, TestInput);
test.equal(input.isValidValue('foo@bar.com'), true);
test.equal(input.isValidValue('foo@bar'), false);
test.done();
-
},
'should be able to use an object as validations property': function (test) {
-
- const TestForm = React.createClass({
+ class TestForm extends React.Component {
render() {
return (
@@ -225,7 +226,8 @@ export default {
);
}
- });
+ }
+
const form = TestUtils.renderIntoDocument();
const input = TestUtils.findRenderedComponentWithType(form, TestInput);
@@ -233,12 +235,10 @@ export default {
test.equal(input.isValidValue('foo@bar'), false);
test.done();
-
},
'should be able to pass complex values to a validation rule': function (test) {
-
- const TestForm = React.createClass({
+ class TestForm extends React.Component {
render() {
return (
@@ -248,7 +248,8 @@ export default {
);
}
- });
+ }
+
const form = TestUtils.renderIntoDocument();
const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
@@ -258,18 +259,18 @@ export default {
test.equal(inputComponent.isValid(), false);
test.done();
-
},
'should be able to run a function to validate': function (test) {
-
- const TestForm = React.createClass({
- customValidationA(values, value) {
+ class TestForm extends React.Component {
+ customValidationA = (values, value) => {
return value === 'foo';
- },
- customValidationB(values, value) {
+ };
+
+ customValidationB = (values, value) => {
return value === 'foo' && values.A === 'foo';
- },
+ };
+
render() {
return (
@@ -282,7 +283,8 @@ export default {
);
}
- });
+ }
+
const form = TestUtils.renderIntoDocument();
const inputComponent = TestUtils.scryRenderedComponentsWithType(form, TestInput);
@@ -294,12 +296,10 @@ export default {
test.equal(inputComponent[1].isValid(), false);
test.done();
-
},
'should not override error messages with error messages passed by form if passed eror messages is an empty object': function (test) {
-
- const TestForm = React.createClass({
+ class TestForm extends React.Component {
render() {
return (
@@ -309,20 +309,19 @@ export default {
);
}
- });
+ }
+
const form = TestUtils.renderIntoDocument();
const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
test.equal(inputComponent.getErrorMessage(), 'bar3');
test.done();
-
},
'should override all error messages with error messages passed by form': function (test) {
-
- const TestForm = React.createClass({
+ class TestForm extends React.Component {
render() {
return (
@@ -332,19 +331,18 @@ export default {
);
}
- });
+ }
+
const form = TestUtils.renderIntoDocument();
const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
test.equal(inputComponent.getErrorMessage(), 'bar');
test.done();
-
},
'should override validation rules with required rules': function (test) {
-
- const TestForm = React.createClass({
+ class TestForm extends React.Component {
render() {
return (
@@ -362,19 +360,18 @@ export default {
);
}
- });
+ }
+
const form = TestUtils.renderIntoDocument();
const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
test.equal(inputComponent.getErrorMessage(), 'bar3');
test.done();
-
},
'should fall back to default error message when non exist in validationErrors map': function (test) {
-
- const TestForm = React.createClass({
+ class TestForm extends React.Component {
render() {
return (
@@ -389,19 +386,18 @@ export default {
);
}
- });
+ }
+
const form = TestUtils.renderIntoDocument();
const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
test.equal(inputComponent.getErrorMessage(), 'bar');
test.done();
-
},
'should not be valid if it is required and required rule is true': function (test) {
-
- const TestForm = React.createClass({
+ class TestForm extends React.Component {
render() {
return (
@@ -411,25 +407,23 @@ export default {
);
}
- });
+ }
+
const form = TestUtils.renderIntoDocument();
const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
test.equal(inputComponent.isValid(), false);
test.done();
-
},
'should handle objects and arrays as values': function (test) {
+ class TestForm extends React.Component {
+ state = {
+ foo: {foo: 'bar'},
+ bar: ['foo']
+ };
- const TestForm = React.createClass({
- getInitialState() {
- return {
- foo: {foo: 'bar'},
- bar: ['foo']
- };
- },
render() {
return (
@@ -438,7 +432,8 @@ export default {
);
}
- });
+ }
+
const form = TestUtils.renderIntoDocument();
form.setState({
@@ -451,22 +446,20 @@ export default {
test.deepEqual(inputs[1].getValue(), ['bar']);
test.done();
-
},
'should handle isFormDisabled with dynamic inputs': function (test) {
+ class TestForm extends React.Component {
+ state = {
+ bool: true
+ };
- const TestForm = React.createClass({
- getInitialState() {
- return {
- bool: true
- };
- },
- flip() {
+ flip = () => {
this.setState({
bool: !this.state.bool
});
- },
+ };
+
render() {
return (
@@ -477,7 +470,8 @@ export default {
);
}
- });
+ }
+
const form = TestUtils.renderIntoDocument();
const input = TestUtils.findRenderedComponentWithType(form, TestInput);
@@ -486,15 +480,14 @@ export default {
test.equal(input.isFormDisabled(), false);
test.done();
-
},
'should allow for dot notation in name which maps to a deep object': function (test) {
-
- const TestForm = React.createClass({
- onSubmit(model) {
+ class TestForm extends React.Component {
+ onSubmit = (model) => {
test.deepEqual(model, {foo: {bar: 'foo', test: 'test'}});
- },
+ };
+
render() {
return (
@@ -503,7 +496,8 @@ export default {
);
}
- });
+ }
+
const form = TestUtils.renderIntoDocument();
test.expect(1);
@@ -512,15 +506,14 @@ export default {
TestUtils.Simulate.submit(formEl);
test.done();
-
},
'should allow for application/x-www-form-urlencoded syntax and convert to object': function (test) {
-
- const TestForm = React.createClass({
- onSubmit(model) {
+ class TestForm extends React.Component {
+ onSubmit = (model) => {
test.deepEqual(model, {foo: ['foo', 'bar']});
- },
+ };
+
render() {
return (
@@ -529,7 +522,8 @@ export default {
);
}
- });
+ }
+
const form = TestUtils.renderIntoDocument();
test.expect(1);
@@ -538,20 +532,18 @@ export default {
TestUtils.Simulate.submit(formEl);
test.done();
-
},
- 'input should rendered once with PureRenderMixin': function (test) {
+ 'input should rendered once with PureComponent': function (test) {
var renderSpy = sinon.spy();
- const Input = InputFactory({
- mixins: [Formsy.Mixin, PureRenderMixin],
+ const Input = class extends TestInput {
render() {
renderSpy();
return ;
}
- });
+ };
const form = TestUtils.renderIntoDocument(
@@ -560,7 +552,6 @@ export default {
);
test.equal(renderSpy.calledOnce, true);
-
test.done();
}
diff --git a/tests/Formsy-spec.js b/tests/Formsy-spec.js
index a1cdc4bf..a2b74dd3 100755
--- a/tests/Formsy-spec.js
+++ b/tests/Formsy-spec.js
@@ -1,6 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom';
-import TestUtils from 'react-addons-test-utils';
+import TestUtils from 'react-dom/test-utils';
import Formsy from './..';
import TestInput from './utils/TestInput';
@@ -12,7 +12,7 @@ export default {
'Setting up a form': {
'should expose the users DOM node through an innerRef prop': function (test) {
- const TestForm = React.createClass({
+ class TestForm extends React.Component {
render() {
return (
@@ -20,7 +20,7 @@ export default {
);
}
- });
+ }
const form = TestUtils.renderIntoDocument();
const input = form.name;
@@ -48,9 +48,9 @@ export default {
},
'should allow for null/undefined children': function (test) {
-
let model = null;
- const TestForm = React.createClass({
+
+ class TestForm extends React.Component {
render() {
return (
(model = formModel)}>
@@ -61,7 +61,7 @@ export default {
);
}
- });
+ }
const form = TestUtils.renderIntoDocument();
immediate(() => {
@@ -69,25 +69,27 @@ export default {
test.deepEqual(model, {name: 'foo'});
test.done();
});
-
+ test.done()
},
'should allow for inputs being added dynamically': function (test) {
-
const inputs = [];
let forceUpdate = null;
let model = null;
- const TestForm = React.createClass({
+
+ class TestForm extends React.Component {
componentWillMount() {
forceUpdate = this.forceUpdate.bind(this);
- },
+ }
+
render() {
return (
(model = formModel)}>
{inputs}
);
}
- });
+ }
+
const form = TestUtils.renderIntoDocument();
// Wait before adding the input
@@ -105,25 +107,26 @@ export default {
});
}, 10);
-
},
'should allow dynamically added inputs to update the form-model': function (test) {
-
const inputs = [];
let forceUpdate = null;
let model = null;
- const TestForm = React.createClass({
+
+ class TestForm extends React.Component {
componentWillMount() {
forceUpdate = this.forceUpdate.bind(this);
- },
+ }
+
render() {
return (
(model = formModel)}>
{inputs}
);
}
- });
+ }
+
const form = TestUtils.renderIntoDocument();
// Wait before adding the input
@@ -143,18 +146,17 @@ export default {
});
});
-
},
'should allow a dynamically updated input to update the form-model': function (test) {
-
let forceUpdate = null;
let model = null;
- const TestForm = React.createClass({
+ class TestForm extends React.Component {
componentWillMount() {
forceUpdate = this.forceUpdate.bind(this);
- },
+ }
+
render() {
const input = ;
@@ -163,7 +165,8 @@ export default {
{input}
);
}
- });
+ }
+
let form = TestUtils.renderIntoDocument();
// Wait before changing the input
@@ -181,7 +184,6 @@ export default {
});
});
-
}
},
@@ -354,18 +356,17 @@ export default {
},
'should not trigger onChange when form is mounted': function (test) {
-
-
const hasChanged = sinon.spy();
- const TestForm = React.createClass({
+
+ class TestForm extends React.Component {
render() {
return ;
}
- });
+ }
+
TestUtils.renderIntoDocument();
test.equal(hasChanged.called, false);
test.done();
-
},
'should trigger onChange once when form element is changed': function (test) {
@@ -383,19 +384,19 @@ export default {
},
'should trigger onChange once when new input is added to form': function (test) {
-
const hasChanged = sinon.spy();
- const TestForm = React.createClass({
- getInitialState() {
- return {
- showInput: false
- };
- },
- addInput() {
+
+ class TestForm extends React.Component {
+ state = {
+ showInput: false
+ };
+
+ addInput = () => {
this.setState({
showInput: true
})
- },
+ };
+
render() {
return (
@@ -407,7 +408,7 @@ export default {
}
);
}
- });
+ }
const form = TestUtils.renderIntoDocument();
form.addInput();
@@ -415,23 +416,22 @@ export default {
test.equal(hasChanged.calledOnce, true);
test.done();
});
-
},
'Update a form': {
'should allow elements to check if the form is disabled': function (test) {
+ class TestForm extends React.Component {
+ state = { disabled: true };
+ enableForm = () => { this.setState({ disabled: false }); };
- const TestForm = React.createClass({
- getInitialState() { return { disabled: true }; },
- enableForm() { this.setState({ disabled: false }); },
render() {
return (
);
}
- });
+ }
const form = TestUtils.renderIntoDocument();
const input = TestUtils.findRenderedComponentWithType(form, TestInput);
@@ -442,23 +442,24 @@ export default {
test.equal(input.isFormDisabled(), false);
test.done();
});
-
},
'should be possible to pass error state of elements by changing an errors attribute': function (test) {
+ class TestForm extends React.Component {
+ state = { validationErrors: { foo: 'bar' } };
- const TestForm = React.createClass({
- getInitialState() { return { validationErrors: { foo: 'bar' } }; },
- onChange(values) {
+ onChange = (values) => {
this.setState(values.foo ? { validationErrors: {} } : { validationErrors: {foo: 'bar'} });
- },
+ };
+
render() {
return (
);
}
- });
+ }
+
const form = TestUtils.renderIntoDocument();
// Wait for update
@@ -473,39 +474,39 @@ export default {
test.done();
});
});
-
},
'should trigger an onValidSubmit when submitting a valid form': function (test) {
-
let isCalled = sinon.spy();
- const TestForm = React.createClass({
+
+ class TestForm extends React.Component {
render() {
return (
);
}
- });
+ }
+
const form = TestUtils.renderIntoDocument();
const FoundForm = TestUtils.findRenderedComponentWithType(form, TestForm);
TestUtils.Simulate.submit(ReactDOM.findDOMNode(FoundForm));
test.equal(isCalled.called,true);
test.done();
-
},
'should trigger an onInvalidSubmit when submitting an invalid form': function (test) {
-
let isCalled = sinon.spy();
- const TestForm = React.createClass({
+
+ class TestForm extends React.Component {
render() {
return (
);
}
- });
+ }
+
const form = TestUtils.renderIntoDocument();
const FoundForm = TestUtils.findRenderedComponentWithType(form, TestForm);
@@ -513,7 +514,6 @@ export default {
test.equal(isCalled.called, true);
test.done();
-
}
},
@@ -521,9 +521,9 @@ export default {
'value === false': {
'should call onSubmit correctly': function (test) {
-
const onSubmit = sinon.spy();
- const TestForm = React.createClass({
+
+ class TestForm extends React.Component {
render() {
return (
@@ -532,29 +532,28 @@ export default {
);
}
- });
+ }
const form = TestUtils.renderIntoDocument();
TestUtils.Simulate.submit(ReactDOM.findDOMNode(form));
test.equal(onSubmit.calledWith({foo: false}), true);
test.done();
-
},
'should allow dynamic changes to false': function (test) {
-
const onSubmit = sinon.spy();
- const TestForm = React.createClass({
- getInitialState() {
- return {
- value: true
- };
- },
- changeValue() {
+
+ class TestForm extends React.Component {
+ state = {
+ value: true
+ };
+
+ changeValue = () => {
this.setState({
value: false
});
- },
+ };
+
render() {
return (
@@ -563,19 +562,17 @@ export default {
);
}
- });
+ }
const form = TestUtils.renderIntoDocument();
form.changeValue();
TestUtils.Simulate.submit(ReactDOM.findDOMNode(form));
test.equal(onSubmit.calledWith({foo: false}), true);
test.done();
-
},
'should say the form is submitted': function (test) {
-
- const TestForm = React.createClass({
+ class TestForm extends React.Component {
render() {
return (
@@ -584,29 +581,28 @@ export default {
);
}
- });
+ }
+
const form = TestUtils.renderIntoDocument();
const input = TestUtils.findRenderedComponentWithType(form, TestInput);
test.equal(input.isFormSubmitted(), false);
TestUtils.Simulate.submit(ReactDOM.findDOMNode(form));
test.equal(input.isFormSubmitted(), true);
test.done();
-
},
'should be able to reset the form to its pristine state': function (test) {
+ class TestForm extends React.Component {
+ state = {
+ value: true
+ };
- const TestForm = React.createClass({
- getInitialState() {
- return {
- value: true
- };
- },
- changeValue() {
+ changeValue = () => {
this.setState({
value: false
});
- },
+ };
+
render() {
return (
@@ -615,7 +611,8 @@ export default {
);
}
- });
+ }
+
const form = TestUtils.renderIntoDocument();
const input = TestUtils.findRenderedComponentWithType(form, TestInput);
const formsyForm = TestUtils.findRenderedComponentWithType(form, Formsy.Form);
@@ -626,22 +623,20 @@ export default {
test.equal(input.getValue(), true);
test.done();
-
},
'should be able to reset the form using custom data': function (test) {
+ class TestForm extends React.Component {
+ state = {
+ value: true
+ };
- const TestForm = React.createClass({
- getInitialState() {
- return {
- value: true
- };
- },
- changeValue() {
+ changeValue = () => {
this.setState({
value: false
});
- },
+ };
+
render() {
return (
@@ -650,7 +645,8 @@ export default {
);
}
- });
+ }
+
const form = TestUtils.renderIntoDocument();
const input = TestUtils.findRenderedComponentWithType(form, TestInput);
const formsyForm = TestUtils.findRenderedComponentWithType(form, Formsy.Form);
@@ -663,14 +659,12 @@ export default {
});
test.equal(input.getValue(), 'bar');
test.done();
-
}
},
'should be able to reset the form to empty values': function (test) {
-
- const TestForm = React.createClass({
+ class TestForm extends React.Component {
render() {
return (
@@ -679,7 +673,8 @@ export default {
);
}
- });
+ }
+
const form = TestUtils.renderIntoDocument();
const input = TestUtils.findRenderedComponentWithType(form, TestInput);
const formsyForm = TestUtils.findRenderedComponentWithType(form, Formsy.Form);
@@ -689,7 +684,6 @@ export default {
});
test.equal(input.getValue(), '');
test.done();
-
},
'.isChanged()': {
diff --git a/tests/Rules-equals-spec.js b/tests/Rules-equals-spec.js
index dc13ad0c..cade3b9f 100644
--- a/tests/Rules-equals-spec.js
+++ b/tests/Rules-equals-spec.js
@@ -1,80 +1,62 @@
-import React from 'react';
-import TestUtils from 'react-addons-test-utils';
-import immediate from './utils/immediate';
+import React from 'react'
+import TestUtils from 'react-dom/test-utils'
+import immediate from './utils/immediate'
-import Formsy from './..';
-import { InputFactory } from './utils/TestInput';
+import Formsy from './..'
+import { ReadOnlyInput } from './utils/TestInput'
-const TestInput = InputFactory({
- render() {
- return ;
- }
-});
-
-const TestForm = React.createClass({
- render() {
+class TestForm extends React.Component {
+ render () {
return (
-
+
- );
+ )
}
-});
+}
export default {
'should pass when the value is equal': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail when the value is not equal': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should pass with an empty string': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with an undefined': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with a null': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail with a number': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
}
-};
+}
diff --git a/tests/Rules-isAlpha-spec.js b/tests/Rules-isAlpha-spec.js
index cfbec5f0..6ef926ec 100644
--- a/tests/Rules-isAlpha-spec.js
+++ b/tests/Rules-isAlpha-spec.js
@@ -1,88 +1,68 @@
-import React from 'react';
-import TestUtils from 'react-addons-test-utils';
+import React from 'react'
+import TestUtils from 'react-dom/test-utils'
-import Formsy from './..';
-import { InputFactory } from './utils/TestInput';
+import Formsy from './..'
+import { ReadOnlyInput } from './utils/TestInput'
-const TestInput = InputFactory({
- render() {
- return ;
- }
-});
-
-const TestForm = React.createClass({
- render() {
+class TestForm extends React.Component {
+ render () {
return (
-
+
- );
+ )
}
-});
+}
export default {
'should pass with a default value': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with a string is only latin letters': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail with a string with numbers': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should pass with an undefined': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with a null': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with an empty string': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail with a number': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
}
-};
+}
diff --git a/tests/Rules-isAlphanumeric-spec.js b/tests/Rules-isAlphanumeric-spec.js
index 5ae5e402..d1a7c797 100644
--- a/tests/Rules-isAlphanumeric-spec.js
+++ b/tests/Rules-isAlphanumeric-spec.js
@@ -1,98 +1,84 @@
-import React from 'react';
-import TestUtils from 'react-addons-test-utils';
+import React from 'react'
+import TestUtils from 'react-dom/test-utils'
-import Formsy from './..';
-import { InputFactory } from './utils/TestInput';
+import Formsy from './..'
+import { ReadOnlyInput } from './utils/ReadOnlyInput'
-const TestInput = InputFactory({
- render() {
- return ;
- }
-});
-
-const TestForm = React.createClass({
- render() {
+class TestForm extends React.Component {
+ render () {
return (
-
+
- );
+ )
}
-});
+}
export default {
'should pass with a default value': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with a string is only latin letters': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail with a string with numbers': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with an undefined': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with a null': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with an empty string': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with a number': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail with a non alpha and number symbols': function (test) {
-
- const value = '!@#$%^&*()';
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
+ const value = '!@#$%^&*()'
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
}
-};
+}
diff --git a/tests/Rules-isEmail-spec.js b/tests/Rules-isEmail-spec.js
index 4696e2ac..59505846 100644
--- a/tests/Rules-isEmail-spec.js
+++ b/tests/Rules-isEmail-spec.js
@@ -1,88 +1,75 @@
-import React from 'react';
-import TestUtils from 'react-addons-test-utils';
+import React from 'react'
+import TestUtils from 'react-dom/test-utils'
-import Formsy from './..';
-import { InputFactory } from './utils/TestInput';
+import Formsy from './..'
+import { ReadOnlyInput } from './utils/TestInput'
-const TestInput = InputFactory({
- render() {
- return ;
- }
-});
-
-const TestForm = React.createClass({
- render() {
+class TestForm extends React.Component {
+ render () {
return (
-
+
- );
+ )
}
-});
+}
export default {
'should pass with a default value': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail with "foo"': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should pass with "foo@foo.com"': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with an undefined': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with a null': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with an empty string': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail with a number': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
}
-};
+}
diff --git a/tests/Rules-isEmptyString-spec.js b/tests/Rules-isEmptyString-spec.js
index a14683fb..7bd51558 100644
--- a/tests/Rules-isEmptyString-spec.js
+++ b/tests/Rules-isEmptyString-spec.js
@@ -1,88 +1,68 @@
-import React from 'react';
-import TestUtils from 'react-addons-test-utils';
+import React from 'react'
+import TestUtils from 'react-dom/test-utils'
-import Formsy from './..';
-import { InputFactory } from './utils/TestInput';
+import Formsy from './..'
+import { ReadOnlyInput } from './utils/ReadOnlyInput'
-const TestInput = InputFactory({
- render() {
- return ;
- }
-});
-
-const TestForm = React.createClass({
- render() {
+class TestForm extends React.Component {
+ render () {
return (
-
+
- );
+ )
}
-});
+}
export default {
'should pass with a default value': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should fail with non-empty string': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should pass with an empty string': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail with undefined': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should fail with null': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should fail with a number': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should fail with a zero': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
}
-};
+}
diff --git a/tests/Rules-isExisty-spec.js b/tests/Rules-isExisty-spec.js
index 76ea729d..169ed033 100644
--- a/tests/Rules-isExisty-spec.js
+++ b/tests/Rules-isExisty-spec.js
@@ -1,88 +1,75 @@
-import React from 'react';
-import TestUtils from 'react-addons-test-utils';
+import React from 'react'
+import TestUtils from 'react-dom/test-utils'
-import Formsy from './..';
-import { InputFactory } from './utils/TestInput';
+import Formsy from './..'
+import { ReadOnlyInput } from './utils/ReadOnlyInput'
-const TestInput = InputFactory({
- render() {
- return ;
- }
-});
-
-const TestForm = React.createClass({
- render() {
+class TestForm extends React.Component {
+ render () {
return (
-
+
- );
+ )
}
-});
+}
export default {
'should pass with a default value': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should pass with a string': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with an empty string': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail with undefined': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should fail with null': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should pass with a number': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with a zero': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
}
-};
+}
diff --git a/tests/Rules-isFloat-spec.js b/tests/Rules-isFloat-spec.js
index 847c1f70..d7c37333 100644
--- a/tests/Rules-isFloat-spec.js
+++ b/tests/Rules-isFloat-spec.js
@@ -1,125 +1,107 @@
-import React from 'react';
-import TestUtils from 'react-addons-test-utils';
+import React from 'react'
+import TestUtils from 'react-dom/test-utils'
-import Formsy from './..';
-import { InputFactory } from './utils/TestInput';
+import Formsy from './..'
+import { ReadOnlyInput } from './utils/ReadOnlyInput'
-const TestInput = InputFactory({
- render() {
- return ;
- }
-});
-
-const TestForm = React.createClass({
- render() {
+class TestForm extends React.Component {
+ render () {
return (
-
+
- );
+ )
}
-});
+}
export default {
'should pass with a default value': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with an empty string': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail with a string': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should pass with a number as string': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail string with digits': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should pass with an int': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with a float': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with a float in science notation': function (test) {
-
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with undefined': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with null': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with a zero': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
}
-};
+}
diff --git a/tests/Rules-isInt-spec.js b/tests/Rules-isInt-spec.js
index 84cbac76..46f7d059 100644
--- a/tests/Rules-isInt-spec.js
+++ b/tests/Rules-isInt-spec.js
@@ -1,125 +1,96 @@
-import React from 'react';
-import TestUtils from 'react-addons-test-utils';
+import React from 'react'
+import TestUtils from 'react-dom/test-utils'
-import Formsy from './..';
-import { InputFactory } from './utils/TestInput';
+import Formsy from './..'
+import { ReadOnlyInput } from './utils/ReadOnlyInput'
-const TestInput = InputFactory({
- render() {
- return ;
- }
-});
-
-const TestForm = React.createClass({
- render() {
+class TestForm extends React.Component {
+ render () {
return (
-
+
- );
+ )
}
-});
+}
export default {
'should pass with a default value': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with an empty string': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail with a string': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should pass with a number as string': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail string with digits': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should pass with an int': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail with a float': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should fail with a float in science notation': function (test) {
-
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should pass with undefined': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with null': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with a zero': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
}
-};
+}
diff --git a/tests/Rules-isLength-spec.js b/tests/Rules-isLength-spec.js
index 74ae2efb..7e05edb3 100644
--- a/tests/Rules-isLength-spec.js
+++ b/tests/Rules-isLength-spec.js
@@ -1,98 +1,84 @@
-import React from 'react';
-import TestUtils from 'react-addons-test-utils';
+import React from 'react'
+import TestUtils from 'react-dom/test-utils'
-import Formsy from './..';
-import { InputFactory } from './utils/TestInput';
+import Formsy from './..'
+import { ReadOnlyInput } from './utils/ReadOnlyInput'
-const TestInput = InputFactory({
- render() {
- return ;
- }
-});
-
-const TestForm = React.createClass({
- render() {
+class TestForm extends React.Component {
+ render () {
return (
-
+
- );
+ )
}
-});
+}
export default {
'isLength:3': {
'should pass with a default value': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail with a string too small': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should fail with a string too long': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should pass with matching length': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with undefined': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with null': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with empty string': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail with a number': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
}
@@ -101,77 +87,69 @@ export default {
'isLength:0': {
'should pass with a default value': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail with a string too small': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should fail with a string too long': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should pass with matching length': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with undefined': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with null': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with empty string': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail with a number': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
}
}
-};
+}
diff --git a/tests/Rules-isNumeric-spec.js b/tests/Rules-isNumeric-spec.js
index 87b15376..7c31b4ad 100644
--- a/tests/Rules-isNumeric-spec.js
+++ b/tests/Rules-isNumeric-spec.js
@@ -1,124 +1,107 @@
-import React from 'react';
-import TestUtils from 'react-addons-test-utils';
+import React from 'react'
+import TestUtils from 'react-dom/test-utils'
-import Formsy from './..';
-import { InputFactory } from './utils/TestInput';
+import Formsy from './..'
+import { ReadOnlyInput } from './utils/ReadOnlyInput'
-const TestInput = InputFactory({
- render() {
- return ;
- }
-});
-
-const TestForm = React.createClass({
- render() {
+class TestForm extends React.Component {
+ render () {
return (
-
+
- );
+ )
}
-});
+}
export default {
'should pass with a default value': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with an empty string': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail with an unempty string': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should pass with a number as string': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail with a number as string with not digits': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should pass with an int': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with a float': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail with a float in science notation': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should pass with an undefined': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with a null': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with a zero': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
}
-};
+}
diff --git a/tests/Rules-isUrl-spec.js b/tests/Rules-isUrl-spec.js
index 0392fadb..db2a7842 100644
--- a/tests/Rules-isUrl-spec.js
+++ b/tests/Rules-isUrl-spec.js
@@ -1,88 +1,67 @@
-import React from 'react';
-import TestUtils from 'react-addons-test-utils';
+import React from 'react'
+import TestUtils from 'react-dom/test-utils'
+import Formsy from './..'
+import { ReadOnlyInput } from './utils/ReadOnlyInput'
-import Formsy from './..';
-import { InputFactory } from './utils/TestInput';
-
-const TestInput = InputFactory({
- render() {
- return ;
- }
-});
-
-const TestForm = React.createClass({
- render() {
+class TestForm extends React.Component {
+ render () {
return (
-
+
- );
+ )
}
-});
+}
export default {
'should pass with default value': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail with "foo"': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should pass with "https://www.google.com/"': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with an undefined': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with a null': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail with a number': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should pass with an empty string': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
}
-};
+}
diff --git a/tests/Rules-isWords-spec.js b/tests/Rules-isWords-spec.js
index f10a80c8..3484d142 100644
--- a/tests/Rules-isWords-spec.js
+++ b/tests/Rules-isWords-spec.js
@@ -1,88 +1,75 @@
-import React from 'react';
-import TestUtils from 'react-addons-test-utils';
+import React from 'react'
+import TestUtils from 'react-dom/test-utils'
-import Formsy from './..';
-import { InputFactory } from './utils/TestInput';
+import Formsy from './..'
+import { ReadOnlyInput } from './utils/ReadOnlyInput'
-const TestInput = InputFactory({
- render() {
- return ;
- }
-});
-
-const TestForm = React.createClass({
- render() {
+class TestForm extends React.Component {
+ render () {
return (
-
+
- );
+ )
}
-});
+}
export default {
'should pass with a default value': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with a 1 word': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with 2 words': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail with a string with numbers': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should pass with an undefined': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with a null': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail with a number': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
}
-};
+}
diff --git a/tests/Rules-maxLength-spec.js b/tests/Rules-maxLength-spec.js
index 61f52798..4b26306f 100644
--- a/tests/Rules-maxLength-spec.js
+++ b/tests/Rules-maxLength-spec.js
@@ -1,97 +1,83 @@
-import React from 'react';
-import TestUtils from 'react-addons-test-utils';
+import React from 'react'
+import TestUtils from 'react-dom/test-utils'
-import Formsy from './..';
-import { InputFactory } from './utils/TestInput';
+import Formsy from './..'
+import { ReadOnlyInput } from './utils/TestInput'
-const TestInput = InputFactory({
- render() {
- return ;
- }
-});
-
-const TestForm = React.createClass({
- render() {
+class TestForm extends React.Component {
+ render () {
return (
-
+
- );
+ )
}
-});
+}
export default {
'should pass with a default value': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass when a string\'s length is smaller': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass when a string\'s length is equal': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail when a string\'s length is bigger': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should pass with empty string': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with an undefined': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with a null': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail with a number': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
}
-};
+}
diff --git a/tests/Rules-minLength-spec.js b/tests/Rules-minLength-spec.js
index 4dd7bd6b..29f42667 100644
--- a/tests/Rules-minLength-spec.js
+++ b/tests/Rules-minLength-spec.js
@@ -1,90 +1,70 @@
-import React from 'react';
-import TestUtils from 'react-addons-test-utils';
+import React from 'react'
+import TestUtils from 'react-dom/test-utils'
-import Formsy from './..';
-import { InputFactory } from './utils/TestInput';
+import Formsy from './..'
+import { ReadOnlyInput } from './utils/ReadOnlyInput'
-const TestInput = InputFactory({
- render() {
- return ;
- }
-});
-
-const TestForm = React.createClass({
- render() {
+class TestForm extends React.Component {
+ render () {
return (
-
+
- );
+ )
}
-});
+}
export default {
'minLength:3': {
'should pass with a default value': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass when a string\'s length is bigger': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail when a string\'s length is smaller': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
},
'should pass with empty string': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with an undefined': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with a null': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail with a number': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
}
},
@@ -92,59 +72,47 @@ export default {
'minLength:0': {
'should pass with a default value': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass when a string\'s length is bigger': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with empty string': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with an undefined': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should pass with a null': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), true);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), true)
+ test.done()
},
'should fail with a number': function (test) {
-
- const form = TestUtils.renderIntoDocument();
- const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
- test.equal(inputComponent.isValid(), false);
- test.done();
-
+ const form = TestUtils.renderIntoDocument()
+ const inputComponent = TestUtils.findRenderedComponentWithType(form, ReadOnlyInput)
+ test.equal(inputComponent.isValid(), false)
+ test.done()
}
}
-};
+}
diff --git a/tests/Validation-spec.js b/tests/Validation-spec.js
index 211c4b5c..60934b07 100644
--- a/tests/Validation-spec.js
+++ b/tests/Validation-spec.js
@@ -1,8 +1,8 @@
import React from 'react';
-import TestUtils from 'react-addons-test-utils';
+import TestUtils from 'react-dom/test-utils';
import Formsy from './..';
-import TestInput, {InputFactory} from './utils/TestInput';
+import TestInput from './utils/TestInput';
import immediate from './utils/immediate';
import sinon from 'sinon';
@@ -93,7 +93,7 @@ export default {
'should be able to use provided validate function': function (test) {
let isValid = false;
- const CustomInput = InputFactory({
+ const CustomInput = class extends TestInput({
componentDidMount() {
isValid = this.isValid();
}
@@ -111,8 +111,7 @@ export default {
},
'should provide invalidate callback on onValiSubmit': function (test) {
-
- const TestForm = React.createClass({
+ class TestForm extends React.Component {
render() {
return (
invalidate({ foo: 'bar' })}>
@@ -120,7 +119,7 @@ export default {
);
}
- });
+ }
const form = TestUtils.renderIntoDocument();
@@ -129,12 +128,10 @@ export default {
TestUtils.Simulate.submit(formEl);
test.equal(input.isValid(), false);
test.done();
-
},
'should provide invalidate callback on onInvalidSubmit': function (test) {
-
- const TestForm = React.createClass({
+ class TestForm extends React.Component {
render() {
return (
invalidate({ foo: 'bar' })}>
@@ -142,7 +139,7 @@ export default {
);
}
- });
+ }
const form = TestUtils.renderIntoDocument();
const formEl = TestUtils.findRenderedDOMComponentWithTag(form, 'form');
@@ -151,12 +148,10 @@ export default {
test.equal(input.getErrorMessage(), 'bar');
test.done();
-
},
'should not invalidate inputs on external errors with preventExternalInvalidation prop': function (test) {
-
- const TestForm = React.createClass({
+ class TestForm extends React.Component {
render() {
return (
);
}
- });
+ }
const form = TestUtils.renderIntoDocument();
const formEl = TestUtils.findRenderedDOMComponentWithTag(form, 'form');
@@ -174,12 +169,10 @@ export default {
TestUtils.Simulate.submit(formEl);
test.equal(input.isValid(), true);
test.done();
-
},
'should invalidate inputs on external errors without preventExternalInvalidation prop': function (test) {
-
- const TestForm = React.createClass({
+ class TestForm extends React.Component {
render() {
return (
invalidate({ foo: 'bar' })}>
@@ -187,7 +180,7 @@ export default {
);
}
- });
+ }
const form = TestUtils.renderIntoDocument();
const formEl = TestUtils.findRenderedDOMComponentWithTag(form, 'form');
@@ -195,7 +188,6 @@ export default {
TestUtils.Simulate.submit(formEl);
test.equal(input.isValid(), false);
test.done();
-
}
};
diff --git a/tests/utils/TestInput.js b/tests/utils/TestInput.js
index d9a57ece..75034607 100644
--- a/tests/utils/TestInput.js
+++ b/tests/utils/TestInput.js
@@ -1,21 +1,26 @@
import React from 'react';
import Formsy from './../..';
-const defaultProps = {
- mixins: [Formsy.Mixin],
- getDefaultProps() {
- return { type: 'text' };
- },
- updateValue(event) {
- this.setValue(event.target[this.props.type === 'checkbox' ? 'checked' : 'value']);
- },
+class TestInput extends React.PureComponent {
+ static defaultProps = {
+ type: 'text'
+ }
+
+ updateValue = (event) => {
+ this.props.setValue(event.target[this.props.type === 'checkbox' ? 'checked' : 'value']);
+ }
+
render() {
- return ;
+ return (
+
+ )
}
-};
+}
-export function InputFactory(props) {
- return React.createClass(Object.assign(defaultProps, props));
+export class ReadOnlyInput extends TestInput {
+ render() {
+ return ;
+ }
}
-export default React.createClass(defaultProps);
+export default Formsy.Mixin(TestInput);
diff --git a/tests/utils/TestInputHoc.js b/tests/utils/TestInputHoc.js
index 085be8f5..0b942d9a 100644
--- a/tests/utils/TestInputHoc.js
+++ b/tests/utils/TestInputHoc.js
@@ -1,13 +1,14 @@
-import React from 'react';
-import { HOC as formsyHoc } from './../..';
+import React from 'react'
+import Formsy from './../..'
-const defaultProps = {
- methodOnWrappedInstance(param) {
- return param;
- },
- render() {
- return ();
- },
-};
+class TestInput extends React.Component {
+ methodOnWrappedInstance (param) {
+ return param
+ }
-export default formsyHoc(React.createClass(defaultProps));
+ render () {
+ return
+ }
+}
+
+export default Formsy.HOC(TestInput)