From 27027bc8a345d08b1520926db331e91017f1fe9d Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Thu, 24 Jun 2021 15:23:31 +0200 Subject: [PATCH] [test] Make remaining testing-library tests StrictMode compatible (#26924) --- .../material-ui/src/Select/Select.test.js | 61 ++++++++++--------- .../src/SpeedDial/SpeedDial.test.js | 13 ++-- .../test/integration/Select.test.js | 2 - 3 files changed, 39 insertions(+), 37 deletions(-) diff --git a/packages/material-ui/src/Select/Select.test.js b/packages/material-ui/src/Select/Select.test.js index 5d8725ce7b1606..467d8a14969ec1 100644 --- a/packages/material-ui/src/Select/Select.test.js +++ b/packages/material-ui/src/Select/Select.test.js @@ -20,9 +20,18 @@ import Divider from '@material-ui/core/Divider'; import classes from './selectClasses'; describe(', () => ({ classes, @@ -150,7 +159,9 @@ describe(', ); const trigger = screen.getByRole('button'); - trigger.focus(); + act(() => { + trigger.focus(); + }); fireEvent.keyDown(trigger, { key }); expect(screen.getByRole('listbox', { hidden: false })).not.to.equal(null); @@ -168,9 +179,13 @@ describe(', ); const button = getByRole('button'); - button.focus(); + act(() => { + button.focus(); + }); - button.blur(); + act(() => { + button.blur(); + }); expect(handleBlur.callCount).to.equal(1); expect(handleBlur.firstCall.returnValue).to.equal('blur-testing'); @@ -245,7 +260,9 @@ describe(', ); fireEvent.mouseDown(getByRole('button')); - getAllByRole('option')[1].click(); + act(() => { + getAllByRole('option')[1].click(); + }); expect(onChangeHandler.calledOnce).to.equal(true); const selected = onChangeHandler.args[0][1]; @@ -264,7 +281,9 @@ describe('', () => { , ); fireEvent.mouseDown(getByRole('button')); - getAllByRole('option')[1].click(); + act(() => { + getAllByRole('option')[1].click(); + }); expect(onChangeHandler.callCount).to.equal(0); }); @@ -562,7 +583,9 @@ describe('', () => { }); describe('prop: MenuProps', () => { - let clock; - - beforeEach(() => { - clock = useFakeTimers(); - }); - - afterEach(() => { - clock.restore(); - }); - it('should apply additional props to the Menu component', () => { const onEntered = spy(); const { getByRole } = render( @@ -661,16 +674,6 @@ describe(' integration', () => { Ten , - // StrictModeViolation: Requires fake timers + act - { strict: false }, ); act(() => {