Skip to content

Commit

Permalink
Re-enable and fix skipped test in time-navigator-component.test.tsx
Browse files Browse the repository at this point in the history
It was skipped after moving to React 18 which enzyme doesn't support.

Signed-off-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
  • Loading branch information
bhufmann committed Apr 4, 2023
1 parent 6c9b620 commit 767b7b0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Time axis component creates canvas 1`] = `
<div>
<div>
<canvas
class="time-graph-canvas horizontal-canvas"
height="10"
id="time-navigator"
style="width: 600px; height: 10px;"
tabindex="0"
width="600"
/>
</div>
</div>
`;
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -18,12 +29,12 @@ describe('Time axis component', () => {
lineColor: 0x757575
}

const wrapper = mount(<TimeNavigatorComponent unitController={unitController} style={style} addWidgetResizeHandler={() => null} removeWidgetResizeHandler={() => null}/>);
expect(wrapper.contains(<TimeNavigatorComponent unitController={unitController} style={style} addWidgetResizeHandler={() => null} removeWidgetResizeHandler={() => null}/>));
render(<div><TimeNavigatorComponent unitController={unitController} style={style} addWidgetResizeHandler={() => null} removeWidgetResizeHandler={() => null} ref={ref}/></div>);
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,
Expand All @@ -33,7 +44,7 @@ describe('Time axis component', () => {
lineColor: 0x757575
}

const wrapper = mount(<TimeNavigatorComponent unitController={unitController} style={style} addWidgetResizeHandler={() => null} removeWidgetResizeHandler={() => null}/>);
expect(wrapper.find('canvas')).toHaveLength(1);
const { container} = render(<div><TimeNavigatorComponent unitController={unitController} style={style} addWidgetResizeHandler={() => null} removeWidgetResizeHandler={() => null} ref={ref}/></div>);
expect(container).toMatchSnapshot();
});
});

0 comments on commit 767b7b0

Please sign in to comment.