From 86544f4b2440abea859df6b14a0283d8ff606737 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 28 Feb 2021 17:21:26 +0100 Subject: [PATCH] Enabled @typescript-eslint/unbound-method eslint rule again --- .eslintrc | 2 +- src/visits/types/helpers.ts | 2 +- test/servers/services/ServersExporter.test.ts | 28 ++++++++----------- test/visits/helpers/DefaultChart.test.tsx | 8 +++--- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/.eslintrc b/.eslintrc index dc1ba2d1..34cf132e 100644 --- a/.eslintrc +++ b/.eslintrc @@ -16,7 +16,7 @@ }, "rules": { "@typescript-eslint/no-unsafe-assignment": "off", - "@typescript-eslint/unbound-method": "off", + "@typescript-eslint/no-unsafe-member-access": "off", "@typescript-eslint/no-unsafe-call": "off", "@typescript-eslint/no-unsafe-return": "off", diff --git a/src/visits/types/helpers.ts b/src/visits/types/helpers.ts index 71a17057..fdc45733 100644 --- a/src/visits/types/helpers.ts +++ b/src/visits/types/helpers.ts @@ -10,6 +10,6 @@ export interface GroupedNewVisits { export const groupNewVisitsByType = pipe( groupBy((newVisit: CreateVisit) => isOrphanVisit(newVisit.visit) ? 'orphanVisits' : 'regularVisits'), - // @ts-ignore-error Type declaration on groupBy is not correct. It can return undefined props + // @ts-expect-error Type declaration on groupBy is not correct. It can return undefined props (result): GroupedNewVisits => ({ orphanVisits: [], regularVisits: [], ...result }), ); diff --git a/test/servers/services/ServersExporter.test.ts b/test/servers/services/ServersExporter.test.ts index f4e689ff..713c843f 100644 --- a/test/servers/services/ServersExporter.test.ts +++ b/test/servers/services/ServersExporter.test.ts @@ -9,16 +9,15 @@ describe('ServersExporter', () => { click: jest.fn(), style: {}, }); + const appendChild = jest.fn(); + const removeChild = jest.fn(); const createWindowMock = (isIe10 = true) => Mock.of({ navigator: { msSaveBlob: isIe10 ? jest.fn() : undefined, }, document: { createElement: jest.fn(() => createLinkMock()), - body: { - appendChild: jest.fn(), - removeChild: jest.fn(), - }, + body: { appendChild, removeChild }, }, }); const storageMock = Mock.of({ @@ -33,15 +32,14 @@ describe('ServersExporter', () => { }, })), }); - const createCsvjsonMock = (throwError = false) => Mock.of({ - toCSV: jest.fn(() => { - if (throwError) { - throw new Error(''); - } - - return ''; - }), + const erroneousToCsv = jest.fn(() => { + throw new Error(''); }); + const createCsvjsonMock = (throwError = false) => Mock.of({ + toCSV: throwError ? erroneousToCsv : jest.fn(() => ''), + }); + + beforeEach(jest.clearAllMocks); describe('exportServers', () => { let originalConsole: Console; @@ -61,12 +59,11 @@ describe('ServersExporter', () => { it('logs an error if something fails', () => { const csvjsonMock = createCsvjsonMock(true); const exporter = new ServersExporter(storageMock, createWindowMock(), csvjsonMock); - const { toCSV } = csvjsonMock; exporter.exportServers(); expect(error).toHaveBeenCalledTimes(1); - expect(toCSV).toHaveBeenCalledTimes(1); + expect(erroneousToCsv).toHaveBeenCalledTimes(1); }); it('makes use of msSaveBlob API when available', () => { @@ -84,8 +81,7 @@ describe('ServersExporter', () => { it('makes use of download link API when available', () => { const windowMock = createWindowMock(false); const exporter = new ServersExporter(storageMock, windowMock, createCsvjsonMock()); - const { document: { createElement, body } } = windowMock; - const { appendChild, removeChild } = body; + const { document: { createElement } } = windowMock; exporter.exportServers(); diff --git a/test/visits/helpers/DefaultChart.test.tsx b/test/visits/helpers/DefaultChart.test.tsx index 49dd8069..2e3a2e7b 100644 --- a/test/visits/helpers/DefaultChart.test.tsx +++ b/test/visits/helpers/DefaultChart.test.tsx @@ -25,7 +25,7 @@ describe('', () => { const { labels, datasets } = doughnut.prop('data') as any; const [{ title, data, backgroundColor, borderColor }] = datasets; - const { legend, legendCallback, scales } = doughnut.prop('options') ?? {}; + const { legend, scales, ...options } = doughnut.prop('options') ?? {}; expect(title).toEqual('The chart'); expect(labels).toEqual(keys(stats)); @@ -46,7 +46,7 @@ describe('', () => { ]); expect(borderColor).toEqual('white'); expect(legend).toEqual({ display: false }); - expect(typeof legendCallback).toEqual('function'); + expect(typeof options.legendCallback).toEqual('function'); expect(scales).toBeUndefined(); expect(cols).toHaveLength(2); }); @@ -61,12 +61,12 @@ describe('', () => { expect(horizontal).toHaveLength(1); const { datasets: [{ backgroundColor, borderColor }] } = horizontal.prop('data') as any; - const { legend, legendCallback, scales } = horizontal.prop('options') ?? {}; + const { legend, scales, ...options } = horizontal.prop('options') ?? {}; expect(backgroundColor).toEqual(MAIN_COLOR_ALPHA); expect(borderColor).toEqual(MAIN_COLOR); expect(legend).toEqual({ display: false }); - expect(legendCallback).toEqual(false); + expect(typeof options.legendCallback).toEqual('boolean'); expect(scales).toEqual({ xAxes: [ {