From 0a6a337a9fb17dc502b808a480c411806677468e Mon Sep 17 00:00:00 2001 From: Quentin Roy Date: Wed, 31 Jan 2024 11:38:30 +0100 Subject: [PATCH] react-experiment: fix render error msgs in tests (#221) --- .../react-experiment/__tests__/run.test.tsx | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/react-experiment/__tests__/run.test.tsx b/packages/react-experiment/__tests__/run.test.tsx index 28b87b0e..4e752d56 100644 --- a/packages/react-experiment/__tests__/run.test.tsx +++ b/packages/react-experiment/__tests__/run.test.tsx @@ -236,24 +236,21 @@ describe('run', () => { ); expect(screen.getByRole('heading')).toHaveTextContent('Type A'); - // I cannot find a way to test rendering errors without React displaying - // them in the console. - console.log( - "Don't worry about the error below, it's unfortunate but expected", - ); + const spy = vi.spyOn(console, 'error'); + spy.mockImplementation(() => {}); + expect(() => { rerender( , ); }).toThrow('Timeline cannot be changed once set'); + + spy.mockRestore(); }); it('throws an error if the run should resume after an non existing task', async () => { - // I cannot find a way to test rendering errors without React displaying - // them in the console. - console.log( - "Don't worry about the error below, it's unfortunate but expected", - ); + const spy = vi.spyOn(console, 'error'); + spy.mockImplementation(() => {}); expect(() => { render( { />, ); }).toThrow('Could not find task to resume after'); + spy.mockRestore(); }); it('throws an error if the same task is completed multiple times', async () => {