From 8468545d52e0668da20904e95a77e90cee5c30b0 Mon Sep 17 00:00:00 2001 From: Darshit Chanpura Date: Wed, 22 May 2024 15:12:25 -0400 Subject: [PATCH] Fixes audit-logging test Signed-off-by: Darshit Chanpura --- .../audit-logging/test/audit-logging.test.tsx | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/public/apps/configuration/panels/audit-logging/test/audit-logging.test.tsx b/public/apps/configuration/panels/audit-logging/test/audit-logging.test.tsx index 3f5c6e8da..0a560bbd3 100644 --- a/public/apps/configuration/panels/audit-logging/test/audit-logging.test.tsx +++ b/public/apps/configuration/panels/audit-logging/test/audit-logging.test.tsx @@ -40,7 +40,12 @@ describe('Audit logs', () => { }; beforeEach(() => { - jest.spyOn(React, 'useState').mockImplementation((initialValue) => [initialValue, setState]); + // jest.spyOn(React, 'useState').mockImplementation((initialValue) => [initialValue, setState]); + jest.spyOn(React, 'useState').mockRestore(); + jest + .spyOn(React, 'useState') + .mockImplementationOnce(() => [[], setState]) + .mockImplementationOnce(() => [false, jest.fn()]); jest.spyOn(React, 'useEffect').mockImplementationOnce((f) => f()); }); @@ -140,7 +145,11 @@ describe('Audit logs', () => { it('render when AuditLoggingSettings.enabled is true', () => { const auditLoggingSettings = { enabled: true }; - jest.spyOn(React, 'useState').mockImplementation(() => [auditLoggingSettings, setState]); + jest.spyOn(React, 'useState').mockRestore(); + jest + .spyOn(React, 'useState') + .mockImplementationOnce(() => [auditLoggingSettings, setState]) + .mockImplementationOnce(() => [false, jest.fn()]); const component = shallow( ); @@ -149,7 +158,11 @@ describe('Audit logs', () => { it('Click Configure button of general setting section', () => { const auditLoggingSettings = { enabled: true }; - jest.spyOn(React, 'useState').mockImplementation(() => [auditLoggingSettings, setState]); + jest.spyOn(React, 'useState').mockRestore(); + jest + .spyOn(React, 'useState') + .mockImplementationOnce(() => [auditLoggingSettings, setState]) + .mockImplementationOnce(() => [false, jest.fn()]); const component = shallow( ); @@ -161,7 +174,11 @@ describe('Audit logs', () => { it('Click Configure button of Compliance settings section', () => { const auditLoggingSettings = { enabled: true }; - jest.spyOn(React, 'useState').mockImplementation(() => [auditLoggingSettings, setState]); + jest.spyOn(React, 'useState').mockRestore(); + jest + .spyOn(React, 'useState') + .mockImplementationOnce(() => [auditLoggingSettings, setState]) + .mockImplementationOnce(() => [false, jest.fn()]); const component = shallow( );