Skip to content

Commit

Permalink
Fix all types in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thebestnom committed May 17, 2023
1 parent 93ec784 commit 0075505
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
24 changes: 12 additions & 12 deletions __tests__/neovis.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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'
});
});
Expand All @@ -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 = {
Expand All @@ -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'
});
});
Expand Down Expand Up @@ -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();
});
});

Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down
6 changes: 3 additions & 3 deletions __tests__/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ export function mockNormalRunSubscribe(records: Neo4jType.Record<{ [key: string]
}

export function mockFullRunSubscribe(cypherIdsAndAnswers: Record<string, { default?: Neo4jType.Record<{ [key: string]: unknown }>[], [id: number]: Neo4jType.Record<{ [key: string]: unknown }>[] } >): void {
Neo4jMock.mockSessionRun.mockImplementation((cypher: string, parameters: { id: number}) => {
Neo4jMock.mockSessionRun.mockImplementation((cypher: string, parameters: Record<string, unknown>) => {
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<ObservablePromise<{ records: Neo4jType.Record<{ [key: string]: unknown }>[] }>> = Promise.resolve({ records });
observablePromise.subscribe = ({ onNext, onCompleted }) => {
records.forEach(onNext);
Expand Down

0 comments on commit 0075505

Please sign in to comment.