diff --git a/.betterer.results b/.betterer.results index 08df5db3e94..8cf81d8d286 100644 --- a/.betterer.results +++ b/.betterer.results @@ -14,8 +14,8 @@ exports[`no enzyme tests`] = { "packages/jaeger-ui-components/src/TracePageHeader/SpanGraph/index.test.tsx:596989456": [ [14, 35, 13, "RegExp match", "2409514259"] ], - "packages/jaeger-ui-components/src/TraceTimelineViewer/ListView/index.test.js:1734982398": [ - [14, 26, 13, "RegExp match", "2409514259"] + "packages/jaeger-ui-components/src/TraceTimelineViewer/ListView/index.test.tsx:3266788928": [ + [14, 56, 13, "RegExp match", "2409514259"] ], "packages/jaeger-ui-components/src/TraceTimelineViewer/TimelineHeaderRow/TimelineColumnResizer.test.js:989353473": [ [15, 17, 13, "RegExp match", "2409514259"] diff --git a/packages/jaeger-ui-components/src/TraceTimelineViewer/ListView/Positions.test.js b/packages/jaeger-ui-components/src/TraceTimelineViewer/ListView/Positions.test.ts similarity index 99% rename from packages/jaeger-ui-components/src/TraceTimelineViewer/ListView/Positions.test.js rename to packages/jaeger-ui-components/src/TraceTimelineViewer/ListView/Positions.test.ts index e000b7e18c0..82f0ae3b2dc 100644 --- a/packages/jaeger-ui-components/src/TraceTimelineViewer/ListView/Positions.test.js +++ b/packages/jaeger-ui-components/src/TraceTimelineViewer/ListView/Positions.test.ts @@ -16,8 +16,9 @@ import Positions from './Positions'; describe('Positions', () => { const bufferLen = 1; - const getHeight = (i) => i * 2 + 2; - let ps; + const getHeight = (i: number) => i * 2 + 2; + + let ps: Positions; beforeEach(() => { ps = new Positions(bufferLen); diff --git a/packages/jaeger-ui-components/src/TraceTimelineViewer/ListView/__snapshots__/index.test.js.snap b/packages/jaeger-ui-components/src/TraceTimelineViewer/ListView/__snapshots__/index.test.tsx.snap similarity index 100% rename from packages/jaeger-ui-components/src/TraceTimelineViewer/ListView/__snapshots__/index.test.js.snap rename to packages/jaeger-ui-components/src/TraceTimelineViewer/ListView/__snapshots__/index.test.tsx.snap diff --git a/packages/jaeger-ui-components/src/TraceTimelineViewer/ListView/index.test.js b/packages/jaeger-ui-components/src/TraceTimelineViewer/ListView/index.test.tsx similarity index 82% rename from packages/jaeger-ui-components/src/TraceTimelineViewer/ListView/index.test.js rename to packages/jaeger-ui-components/src/TraceTimelineViewer/ListView/index.test.tsx index 55fa6848dfa..3a55a264c83 100644 --- a/packages/jaeger-ui-components/src/TraceTimelineViewer/ListView/index.test.js +++ b/packages/jaeger-ui-components/src/TraceTimelineViewer/ListView/index.test.tsx @@ -12,18 +12,30 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { mount, shallow } from 'enzyme'; +import { mount, ReactWrapper, shallow, ShallowWrapper } from 'enzyme'; import React from 'react'; +import { TNil } from '../../types'; import { polyfill as polyfillAnimationFrame } from '../../utils/test/requestAnimationFrame'; -import ListView from './index'; +import ListView, { TListViewProps } from './index'; // Util to get list of all callbacks added to an event emitter by event type. // jest adds "error" event listeners to window, this util makes it easier to // ignore those calls. -function getListenersByType(mockFn) { - const rv = {}; +function getListenersByType( + mockFn: jest.MockContext< + void, + [ + type: string, + listener: EventListenerOrEventListenerObject, + options?: boolean | AddEventListenerOptions | undefined + ] + > +) { + const rv: { + [eventType: string]: EventListenerOrEventListenerObject[]; + } = {}; mockFn.calls.forEach(([eventType, callback]) => { if (!rv[eventType]) { rv[eventType] = [callback]; @@ -40,25 +52,24 @@ describe('', () => { const DATA_LENGTH = 40; - function getHeight(index) { + function getHeight(index: number) { return index * 2 + 2; } - function Item(props) { + function Item(props: React.HTMLProps) { const { children, ...rest } = props; return
{children}
; } - function renderItem(itemKey, styles, itemIndex, attrs) { + const renderItem: TListViewProps['itemRenderer'] = (itemKey, styles, itemIndex, attrs) => { return ( {itemIndex} ); - } + }; - let wrapper; - let instance; + let instance: ListView; const props = { dataLength: DATA_LENGTH, @@ -74,6 +85,7 @@ describe('', () => { }; describe('shallow tests', () => { + let wrapper: ShallowWrapper; beforeEach(() => { wrapper = shallow(); }); @@ -92,10 +104,10 @@ describe('', () => { it('sets the height of the items according to the height func', () => { const items = wrapper.find(Item); - const expectedHeights = []; + const expectedHeights: number[] = []; const heights = items.map((node, i) => { expectedHeights.push(getHeight(i)); - return node.prop('style').height; + return node.prop('style')?.height; }); expect(heights.length).toBe(props.initialDraw); expect(heights).toEqual(expectedHeights); @@ -109,12 +121,13 @@ describe('', () => { }); describe('mount tests', () => { + let wrapper: ReactWrapper; describe('accessor functions', () => { const clientHeight = 2; const scrollTop = 3; - let oldRender; - let oldInitWrapper; + let oldRender: () => JSX.Element; + let oldInitWrapper: (elm: HTMLElement | TNil) => void; const initWrapperMock = jest.fn((elm) => { if (elm != null) { // jsDom requires `defineProperties` instead of just setting the props @@ -173,14 +186,28 @@ describe('', () => { }); describe('windowScroller', () => { - let windowAddListenerSpy; - let windowRmListenerSpy; + let windowAddListenerSpy: jest.SpyInstance< + void, + [ + type: string, + listener: EventListenerOrEventListenerObject, + options?: boolean | AddEventListenerOptions | undefined + ] + >; + let windowRmListenerSpy: jest.SpyInstance< + void, + [ + type: string, + listener: EventListenerOrEventListenerObject, + options?: boolean | AddEventListenerOptions | undefined + ] + >; beforeEach(() => { windowAddListenerSpy = jest.spyOn(window, 'addEventListener'); windowRmListenerSpy = jest.spyOn(window, 'removeEventListener'); const wsProps = { ...props, windowScroller: true }; - wrapper = mount(); + wrapper = mount(); instance = wrapper.instance(); }); diff --git a/packages/jaeger-ui-components/src/TraceTimelineViewer/ListView/index.tsx b/packages/jaeger-ui-components/src/TraceTimelineViewer/ListView/index.tsx index e7587f0a563..86b93470428 100644 --- a/packages/jaeger-ui-components/src/TraceTimelineViewer/ListView/index.tsx +++ b/packages/jaeger-ui-components/src/TraceTimelineViewer/ListView/index.tsx @@ -27,7 +27,7 @@ type TWrapperProps = { /** * @typedef */ -type TListViewProps = { +export type TListViewProps = { /** * Number of elements in the list. */