From 5aec09115607eb19473d2a58ba7d50df612ce93e Mon Sep 17 00:00:00 2001 From: Attiya Ishaque Date: Fri, 2 Jun 2023 17:49:40 +0500 Subject: [PATCH] fix: fix console errors on running test (#930) --- .../tests/UnAuthOnlyRoute.test.jsx | 13 +++++++++---- src/field-renderer/tests/FieldRenderer.test.jsx | 2 +- src/reset-password/tests/ResetPasswordPage.test.jsx | 11 +++++++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/common-components/tests/UnAuthOnlyRoute.test.jsx b/src/common-components/tests/UnAuthOnlyRoute.test.jsx index 4ea33c38..06b7f310 100644 --- a/src/common-components/tests/UnAuthOnlyRoute.test.jsx +++ b/src/common-components/tests/UnAuthOnlyRoute.test.jsx @@ -4,6 +4,7 @@ import React from 'react'; import { fetchAuthenticatedUser, getAuthenticatedUser } from '@edx/frontend-platform/auth'; import { mount } from 'enzyme'; +import { act } from 'react-dom/test-utils'; import { UnAuthOnlyRoute } from '..'; import { LOGIN_PAGE } from '../../data/constants'; @@ -42,7 +43,7 @@ describe('UnAuthOnlyRoute', () => { jest.clearAllMocks(); }); - it('should have called with forceRefresh true', () => { + it('should have called with forceRefresh true', async () => { const user = { username: 'gonzo', other: 'data', @@ -51,16 +52,20 @@ describe('UnAuthOnlyRoute', () => { getAuthenticatedUser.mockReturnValue(user); fetchAuthenticatedUser.mockReturnValueOnce(Promise.resolve(user)); - mount(routerWrapper()); + await act(async () => { + await mount(routerWrapper()); + }); expect(fetchAuthenticatedUser).toBeCalledWith({ forceRefresh: true }); }); - it('should have called with forceRefresh false', () => { + it('should have called with forceRefresh false', async () => { getAuthenticatedUser.mockReturnValue(null); fetchAuthenticatedUser.mockReturnValueOnce(Promise.resolve(null)); - mount(routerWrapper()); + await act(async () => { + await mount(routerWrapper()); + }); expect(fetchAuthenticatedUser).toBeCalledWith({ forceRefresh: false }); }); diff --git a/src/field-renderer/tests/FieldRenderer.test.jsx b/src/field-renderer/tests/FieldRenderer.test.jsx index d2ac1991..2bad91ff 100644 --- a/src/field-renderer/tests/FieldRenderer.test.jsx +++ b/src/field-renderer/tests/FieldRenderer.test.jsx @@ -25,7 +25,7 @@ describe('FieldRendererTests', () => { type: 'select', label: 'Year of Birth', name: 'yob-field', - options: [['1997', 1997], ['1998', 1998]], + options: [['1997', '1997'], ['1998', '1998']], }; const fieldRenderer = mount(); diff --git a/src/reset-password/tests/ResetPasswordPage.test.jsx b/src/reset-password/tests/ResetPasswordPage.test.jsx index 27eb1f33..facdb5a1 100644 --- a/src/reset-password/tests/ResetPasswordPage.test.jsx +++ b/src/reset-password/tests/ResetPasswordPage.test.jsx @@ -166,11 +166,14 @@ describe('ResetPasswordPage', () => { resetPasswordPage.find('input#newPassword').simulate('blur', { target: { value: 'aziz156', name: 'newPassword' } }); expect(resetPasswordPage.find('div[feedback-for="newPassword"]').text()).toEqual(expectedText); }); - it('should not call validation when typing and click on show icon button', () => { + it('should not call validation when typing and click on show icon button', async () => { const resetPasswordPage = mount(reduxWrapper()); - resetPasswordPage.find('input#newPassword').simulate('change', { target: { value: 'aziz156@', name: 'newPassword' } }); - resetPasswordPage.find('button[aria-label="Show password"]').at(0).simulate('click'); - resetPasswordPage.find('button[aria-label="Hide password"]').at(0).simulate('blur'); + await act(async () => { + await resetPasswordPage.find('input#newPassword').simulate('change', { target: { value: 'aziz156@', name: 'newPassword' } }); + await resetPasswordPage.find('button[aria-label="Show password"]').at(0).simulate('click'); + await resetPasswordPage.find('button[aria-label="Hide password"]').at(0).simulate('blur'); + }); + expect(resetPasswordPage.find('div[feedback-for="newPassword"]').exists()).toBe(false); }); it('should call validation click on show icon button and then focus out', () => {