From 767b7b0c986d2e7b646825fbaf3459da12a3ddf0 Mon Sep 17 00:00:00 2001 From: Bernd Hufmann Date: Tue, 4 Apr 2023 09:50:26 -0400 Subject: [PATCH] Re-enable and fix skipped test in time-navigator-component.test.tsx It was skipped after moving to React 18 which enzyme doesn't support. Signed-off-by: Bernd Hufmann --- .../time-navigator-component.test.tsx.snap | 16 +++++++++ .../time-navigator-component.test.tsx | 35 ++++++++++++------- 2 files changed, 39 insertions(+), 12 deletions(-) create mode 100644 packages/react-components/src/components/utils/__tests__/__snapshots__/time-navigator-component.test.tsx.snap diff --git a/packages/react-components/src/components/utils/__tests__/__snapshots__/time-navigator-component.test.tsx.snap b/packages/react-components/src/components/utils/__tests__/__snapshots__/time-navigator-component.test.tsx.snap new file mode 100644 index 000000000..527bdc531 --- /dev/null +++ b/packages/react-components/src/components/utils/__tests__/__snapshots__/time-navigator-component.test.tsx.snap @@ -0,0 +1,16 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Time axis component creates canvas 1`] = ` +
+
+ +
+
+`; diff --git a/packages/react-components/src/components/utils/__tests__/time-navigator-component.test.tsx b/packages/react-components/src/components/utils/__tests__/time-navigator-component.test.tsx index 194dc1d2c..a4f540548 100644 --- a/packages/react-components/src/components/utils/__tests__/time-navigator-component.test.tsx +++ b/packages/react-components/src/components/utils/__tests__/time-navigator-component.test.tsx @@ -1,14 +1,25 @@ import * as React from 'react'; -import { cleanup } from '@testing-library/react'; +import { cleanup, render } from '@testing-library/react'; import { TimeNavigatorComponent } from '../time-navigator-component'; import { TimeGraphUnitController } from 'timeline-chart/lib/time-graph-unit-controller'; -import { mount } from 'enzyme'; - -afterEach(cleanup); describe('Time axis component', () => { - // Skip until a replacement for Enzyme that works with React 18 is found - it.skip('renders with provided style', () => { + + let axisComponent: any; + const ref = (el: TimeNavigatorComponent | undefined | null): void => { + axisComponent = el; + }; + + beforeEach(() => { + axisComponent = null; + }); + + afterEach(() => { + cleanup(); + jest.clearAllMocks(); + }); + + it('renders with provided style', () => { const unitController: TimeGraphUnitController = new TimeGraphUnitController(BigInt(10), { start: BigInt(0), end: BigInt(10)}); const style = { width: 600, @@ -18,12 +29,12 @@ describe('Time axis component', () => { lineColor: 0x757575 } - const wrapper = mount( null} removeWidgetResizeHandler={() => null}/>); - expect(wrapper.contains( null} removeWidgetResizeHandler={() => null}/>)); + render(
null} removeWidgetResizeHandler={() => null} ref={ref}/>
); + expect(axisComponent).toBeTruthy(); + expect(axisComponent instanceof TimeNavigatorComponent).toBe(true); }); - // Skip until a replacement for Enzyme that works with React 18 is found - it.skip('creates canvas', () => { + it('creates canvas', () => { const unitController: TimeGraphUnitController = new TimeGraphUnitController(BigInt(10), { start: BigInt(0), end: BigInt(10)}); const style = { width: 600, @@ -33,7 +44,7 @@ describe('Time axis component', () => { lineColor: 0x757575 } - const wrapper = mount( null} removeWidgetResizeHandler={() => null}/>); - expect(wrapper.find('canvas')).toHaveLength(1); + const { container} = render(
null} removeWidgetResizeHandler={() => null} ref={ref}/>
); + expect(container).toMatchSnapshot(); }); });