From 00755054465c714829eb91b652759cd93b32e078 Mon Sep 17 00:00:00 2001 From: TheBestNom Date: Fri, 12 May 2023 18:38:06 +0300 Subject: [PATCH] Fix all types in tests --- __tests__/neovis.tests.ts | 24 ++++++++++++------------ __tests__/testUtils.ts | 6 +++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/__tests__/neovis.tests.ts b/__tests__/neovis.tests.ts index cebb2fa..2e66006 100644 --- a/__tests__/neovis.tests.ts +++ b/__tests__/neovis.tests.ts @@ -50,7 +50,7 @@ describe('Neovis', () => { } }; const neovis = new Neovis(config as NeovisConfig); - expect(neovis._config.labels.a).toMatchObject({ label: 'name', chosen: 'test' }); + expect(neovis._config.labels!.a).toMatchObject({ label: 'name', chosen: 'test' }); }); it('should not change the config sent', () => { config = { @@ -87,7 +87,7 @@ describe('Neovis', () => { } }; const neovis = new Neovis(config as NeovisConfig); - expect(neovis._config.relationships.a).toMatchObject({ + expect(neovis._config.relationships!.a).toMatchObject({ label: 'name', color: 'test', chosen: 'overridden' }); }); @@ -101,7 +101,7 @@ describe('Neovis', () => { } }; const neovis = new Neovis(config as NeovisConfig); - expect(neovis._config.labels.a).toMatchObject({ label: 'name', chosen: 'test' }); + expect(neovis._config.labels!.a).toMatchObject({ label: 'name', chosen: 'test' }); }); it('should override default config if specific relationship have one', () => { config.relationships = { @@ -115,7 +115,7 @@ describe('Neovis', () => { } }; const neovis = new Neovis(config as NeovisConfig); - expect(neovis._config.relationships.a).toMatchObject({ + expect(neovis._config.relationships!.a).toMatchObject({ label: 'name', value: 'test', chosen: 'overridden' }); }); @@ -206,9 +206,9 @@ describe('Neovis', () => { ]); neovis.render(); await testUtils.neovisRenderDonePromise(neovis); - expect(neovis.nodes.get(1).raw).toBeDefined(); - expect(neovis.nodes.get(2).raw).toBeDefined(); - expect(neovis.edges.get(3).raw).toBeDefined(); + expect(neovis.nodes.get(1)!.raw).toBeDefined(); + expect(neovis.nodes.get(2)!.raw).toBeDefined(); + expect(neovis.edges.get(3)!.raw).toBeDefined(); }); }); @@ -371,9 +371,9 @@ describe('Neovis', () => { neovis.render(); await testUtils.neovisRenderDonePromise(neovis); - expect(neovis.nodes.get(1).font).toBeDefined(); - expect((neovis.nodes.get(1).font as VisNetwork.Font).size).toBe(fontSize); - expect((neovis.nodes.get(1).font as VisNetwork.Font).color).toBe(fontColor); + expect(neovis.nodes.get(1)!.font).toBeDefined(); + expect((neovis.nodes.get(1)!.font as VisNetwork.Font).size).toBe(fontSize); + expect((neovis.nodes.get(1)!.font as VisNetwork.Font).color).toBe(fontColor); }); it('font field for type not specified in config should not reflect in node data', async () => { @@ -420,8 +420,8 @@ describe('Neovis', () => { await testUtils.neovisRenderDonePromise(neovis); expect(Neo4jMock.mockSessionRun).toHaveBeenCalledTimes(1); expect(neovis.nodes.get(1)).toHaveProperty('font'); - expect(neovis.nodes.get(1).font).toHaveProperty('size', intPropertyValue); - expect(neovis.nodes.get(1).font).toHaveProperty('color', intPropertyValue); + expect(neovis.nodes.get(1)!.font).toHaveProperty('size', intPropertyValue); + expect(neovis.nodes.get(1)!.font).toHaveProperty('color', intPropertyValue); }); it('should merge static type to vis.js config properly', async () => { diff --git a/__tests__/testUtils.ts b/__tests__/testUtils.ts index 6a69216..5892aea 100644 --- a/__tests__/testUtils.ts +++ b/__tests__/testUtils.ts @@ -69,14 +69,14 @@ export function mockNormalRunSubscribe(records: Neo4jType.Record<{ [key: string] } export function mockFullRunSubscribe(cypherIdsAndAnswers: Record[], [id: number]: Neo4jType.Record<{ [key: string]: unknown }>[] } >): void { - Neo4jMock.mockSessionRun.mockImplementation((cypher: string, parameters: { id: number}) => { + Neo4jMock.mockSessionRun.mockImplementation((cypher: string, parameters: Record) => { if (!cypherIdsAndAnswers[cypher]) { throw new Error(`the cypher '${cypher}' was not expected`); } - if (!cypherIdsAndAnswers[cypher].default && !cypherIdsAndAnswers[cypher][parameters.id]) { + if (!cypherIdsAndAnswers[cypher].default && !cypherIdsAndAnswers[cypher][parameters.id as number]) { throw new Error(`the id '${parameters.id}' was not expected for cypher ${cypher}`); } - const records = cypherIdsAndAnswers[cypher].default || cypherIdsAndAnswers[cypher][parameters.id]; + const records = cypherIdsAndAnswers[cypher].default || cypherIdsAndAnswers[cypher][parameters.id as number]; const observablePromise: Partial[] }>> = Promise.resolve({ records }); observablePromise.subscribe = ({ onNext, onCompleted }) => { records.forEach(onNext);