Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Fix life cycle warnings #159

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions __test__/AvBaseInput.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,41 +74,41 @@ describe('BaseInput', function() {
describe('component will mount', () => {
it('should get the default value', () => {
const spy = sinon.spy(this.component, 'getDefaultValue');
this.component.componentWillMount();
this.component.UNSAFE_componentWillMount();
expect(spy).to.have.been.calledOnce;
});

it('should set the value to the default value', () => {
const defaultValue = 'some value';
this.component.props.defaultValue = defaultValue;
this.component.componentWillMount();
this.component.UNSAFE_componentWillMount();
expect(this.component.value).to.equal(defaultValue);
});

it('should set the state value to the default value', () => {
const defaultValue = 'some value';
this.component.props.defaultValue = defaultValue;
this.component.componentWillMount();
this.component.UNSAFE_componentWillMount();
expect(this.setStateSpy).to.have.been.calledWithMatch({ value: defaultValue });
});

it('should set the value to the value prop if provided', () => {
const defaultValue = 'some value';
this.component.props.value = defaultValue;
this.component.componentWillMount();
this.component.UNSAFE_componentWillMount();
expect(this.component.value).to.equal(defaultValue);
});

it('should set the state value to the value prop if provided', () => {
const defaultValue = 'some value';
this.component.props.value = defaultValue;
this.component.componentWillMount();
this.component.UNSAFE_componentWillMount();
expect(this.setStateSpy).to.have.been.calledWithMatch({ value: defaultValue });
});

it('should trigger validation', () => {
const spy = sinon.spy(this.component, 'validate');
this.component.componentWillMount();
this.component.UNSAFE_componentWillMount();
expect(spy).to.have.been.calledOnce;
});
});
Expand All @@ -117,41 +117,41 @@ describe('BaseInput', function() {
it('should do nothing if the value has not changed', () => {
this.props.value = 123;
const spy = sinon.spy(this.component, 'validate');
this.component.componentWillReceiveProps(this.props);
this.component.UNSAFE_componentWillReceiveProps(this.props);
expect(this.setStateSpy).to.not.have.been.called;
expect(spy).to.not.have.been.called;
});

describe('when the value changed', () => {
it('should set the value to the new value', () => {
const newValue = 2342;
this.component.componentWillReceiveProps({ value: newValue });
this.component.UNSAFE_componentWillReceiveProps({ value: newValue });
expect(this.component.value).to.equal(newValue);
});

it('should set the state value to the default value', () => {
const newValue = 2342;
this.component.componentWillReceiveProps({ value: newValue });
this.component.UNSAFE_componentWillReceiveProps({ value: newValue });
expect(this.setStateSpy).to.have.been.calledWithMatch({ value: newValue });
});

it('should trigger validation', () => {
const newValue = 2342;
const spy = sinon.spy(this.component, 'validate');
this.component.componentWillReceiveProps({ value: newValue });
this.component.UNSAFE_componentWillReceiveProps({ value: newValue });
expect(spy).to.have.been.calledOnce;
});

it('should reset the value if multiple has changed from false to true', () => {
this.props.multiple = false;
this.component.componentWillReceiveProps({multiple: true});
this.component.UNSAFE_componentWillReceiveProps({multiple: true});
expect(this.component.value).to.be.empty;
expect(this.component.state.value).to.be.empty;
});

it('should reset the value if multiple has changed from true to false', () => {
this.props.multiple = true;
this.component.componentWillReceiveProps({multiple: false});
this.component.UNSAFE_componentWillReceiveProps({multiple: false});
expect(this.component.value).to.equal('');
});
});
Expand All @@ -160,7 +160,7 @@ describe('BaseInput', function() {
describe('when the checked prop changes', () => {
it('should set the value to the trueValue when the next props checked prop is true', () => {
this.props.checked = false;
this.component.componentWillReceiveProps({
this.component.UNSAFE_componentWillReceiveProps({
type: 'checkbox',
checked: true,
trueValue: true,
Expand All @@ -171,7 +171,7 @@ describe('BaseInput', function() {

it('should set the value to the falseValue when the next props checked prop is false', () => {
this.props.checked = true;
this.component.componentWillReceiveProps({
this.component.UNSAFE_componentWillReceiveProps({
type: 'checkbox',
checked: false,
trueValue: true,
Expand All @@ -182,7 +182,7 @@ describe('BaseInput', function() {

it('should set the state to the new value', () => {
this.props.checked = false;
this.component.componentWillReceiveProps({
this.component.UNSAFE_componentWillReceiveProps({
type: 'checkbox',
checked: true,
trueValue: true,
Expand All @@ -195,7 +195,7 @@ describe('BaseInput', function() {
describe('when the checked prop changes', () => {
it('should not set the state', () => {
this.props.checked = true;
this.component.componentWillReceiveProps({
this.component.UNSAFE_componentWillReceiveProps({
type: 'checkbox',
checked: true,
trueValue: true,
Expand Down
2 changes: 1 addition & 1 deletion __test__/AvInputContainer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('BaseInput', function() {

describe('component will mount', () => {
it('should get the default value', () => {
this.component.componentWillMount();
this.component.UNSAFE_componentWillMount();
expect(this.component._inputs).to.eql({});
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/AvBaseInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ export default class AvBaseInput extends Component {
this.validate = this.validate.bind(this);
}

componentWillMount() {
UNSAFE_componentWillMount() {
this.value = this.props.value || this.getDefaultValue();
this.setState({ value: this.value });
this.updateValidations();
}

componentWillReceiveProps(nextProps) {
UNSAFE_componentWillReceiveProps(nextProps) {
if (nextProps.name !== this.props.name) {
this.context.FormCtrl.unregister(this);
}
Expand Down
4 changes: 2 additions & 2 deletions src/AvCheckboxGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ export default class AvCheckboxGroup extends Component {
};
}

componentWillMount() {
UNSAFE_componentWillMount() {
this.value = this.props.value || this.getDefaultValue().value;
this.setState({ value: this.value });
this.updateValidations();
}

componentWillReceiveProps(nextProps) {
UNSAFE_componentWillReceiveProps(nextProps) {
if (nextProps.name !== this.props.name) {
this.context.FormCtrl.unregister(this);
}
Expand Down
4 changes: 2 additions & 2 deletions src/AvForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ export default class AvForm extends InputContainer {
this._isMounted = false;
}

componentWillMount() {
UNSAFE_componentWillMount() {
this._isMounted = true;
super.componentWillMount();
super.UNSAFE_componentWillMount();

this._validators = {};
}
Expand Down
2 changes: 1 addition & 1 deletion src/AvInputContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function validComponent(input) {
}

export default class InputContainer extends Component {
componentWillMount() {
UNSAFE_componentWillMount() {
this._updaters = {};
this._inputs = {};
}
Expand Down
4 changes: 2 additions & 2 deletions src/AvRadioGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ export default class AvRadioGroup extends Component {
};
}

componentWillMount() {
UNSAFE_componentWillMount() {
this.value = this.props.value || this.getDefaultValue().value;
this.setState({ value: this.value });
this.updateValidations();
}

componentWillReceiveProps(nextProps) {
UNSAFE_componentWillReceiveProps(nextProps) {
if (nextProps.name !== this.props.name) {
this.context.FormCtrl.unregister(this);
}
Expand Down