Skip to content

Commit 0d3113b

Browse files
committed
[fix] Fixted tests
1 parent 55f8244 commit 0d3113b

2 files changed

Lines changed: 26 additions & 12 deletions

File tree

client/components/mobile-phone-change/mobile-phone-change.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,21 @@ class MobilePhoneChange extends React.Component {
3333
phone_number: "",
3434
errors: {},
3535
};
36+
this.isComponentMounted = true;
3637
this.handleSubmit = this.handleSubmit.bind(this);
3738
this.handleChange = this.handleChange.bind(this);
3839
}
3940

41+
setStateSafe(state, callback) {
42+
if (this.isComponentMounted) {
43+
this.setState(state, callback);
44+
}
45+
}
46+
47+
componentWillUnmount() {
48+
this.isComponentMounted = false;
49+
}
50+
4051
async componentDidMount() {
4152
const {setLoading} = this.context;
4253
const {cookies, orgSlug, setUserData, logout, setTitle, orgName, language} =
@@ -55,9 +66,11 @@ class MobilePhoneChange extends React.Component {
5566
if (isValid) {
5667
({userData} = this.props);
5768
const {phone_number} = userData;
58-
this.setState({phone_number});
69+
this.setStateSafe({phone_number});
70+
}
71+
if (this.isComponentMounted) {
72+
setLoading(false);
5973
}
60-
setLoading(false);
6174
}
6275

6376
handleSubmit(event) {

client/components/mobile-phone-change/mobile-phone-change.test.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -423,16 +423,6 @@ describe("Change Phone Number: corner cases", () => {
423423
expect(wrapper.find(StatusMock)).toHaveLength(0);
424424
});
425425

426-
it("should redirect if user registration method is pending_verification", async () => {
427-
validateToken.mockReturnValue(true);
428-
props.userData = userData;
429-
props.userData.is_active = true;
430-
props.userData.method = "pending_verification";
431-
props.settings.mobile_phone_verification = true;
432-
wrapper = await mountComponent(props);
433-
expect(wrapper.find(StatusMock)).toHaveLength(1);
434-
});
435-
436426
it("should validate token", async () => {
437427
wrapper = await mountComponent(props);
438428
expect(validateToken).toHaveBeenCalledWith(
@@ -444,6 +434,17 @@ describe("Change Phone Number: corner cases", () => {
444434
props.language,
445435
);
446436
});
437+
438+
it("should redirect if user registration method is pending_verification", async () => {
439+
validateToken.mockReturnValue(true);
440+
props.userData = userData;
441+
props.userData.is_active = true;
442+
props.userData.method = "pending_verification";
443+
props.settings.mobile_phone_verification = true;
444+
wrapper = await mountComponent(props);
445+
expect(wrapper.find(StatusMock)).toHaveLength(1);
446+
});
447+
447448
it("should redirect if mobile_phone_verification disabled", async () => {
448449
props.settings.mobile_phone_verification = false;
449450
wrapper = await mountComponent(props);

0 commit comments

Comments
 (0)