question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Record type issue

See original GitHub issue

Getting this error when using Record in my unit tests

[tsserver 2351] [E] This expression is not constructable. Type ‘Record’ has no construct signatures.

Driver version: JS driver 4.1.2

Steps to reproduce

driver.ts

import neo4j, { Driver } from "neo4j-driver";
import environment from "./environment";

const driver: Driver = neo4j.driver(
  environment.neo4j.uri,
  neo4j.auth.basic(environment.neo4j.user, environment.neo4j.password)
);
driver.verifyConnectivity().then((param) => console.dir(param));

export default driver;

simplified User.ts

const generateUserModel = (user: JwtUser): TUserModel => ({
  canUpdateRoleFor: async ({ id, role }) => {
    const session = driver.session();
    try {
      const result = await session.run(
        "MATCH (u:User {id: $id}) RETURN u.role",
        { id }
      );
      const currentRole: Role = result.records[0].get(0);
      return currentRole
    } finally {
      await session.close();
    }

User.spec.ts

import { types } from "neo4j-driver";
const { Record } = types; // Strange, but I can't import Record directly from neo4j-driver

jest.mock("../driver", () => {
  // Mock driver.session() used in canUpdateRoleFor
  return {
    __esModule: true,
    default: {
      session: jest.fn(() => ({
        run: jest.fn((_cypher, { id }) => {
          return {
            records: [new Record(["role"], [SortedRoles[id]])], // <= LINE RAISING THE TYPE ERROR
          };
        }),
        close: jest.fn(),
      })),
    },
  };
});

Expected behavior

No type error

Actual behavior

I verified that the implementation is correct and my tests pass as expected.

Also, I cannot find the reason for this error in the code. When jumping to the type definition, I can see a constructor definition.

neo4j-driver/types/record.d.ts

declare class Record {
  keys: string[]
  length: number

  constructor(
    keys: string[],
    fields: any[],
    fieldLookup?: { [index: string]: string }
  )

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
AdrienLemairecommented, Mar 16, 2021

@bigmontz looking forward to 4.3, as it’ll finally allow me to write unittests with a mocked driver.

0reactions
bigmontzcommented, Mar 9, 2021

It will be solved in the 4.3

Read more comments on GitHub >

github_iconTop Results From Across the Web

Considerations for Creating and Updating Record Types and ...
If each profile is associated with a single record type, users will never be prompted to select a record type when creating records....
Read more >
Salesforce Record Type Best Practices + Tutorial
Tutorial: Learn some best practices on using Record Types correctly ... Support Cases based on Issue: Enhancement, Bug; Quote Type: Direct, ...
Read more >
Error in entity based record - Discussions - Appian Community
Hi All, We are facing a issue while loading "Record" list view, getting this error. The Requested Record Type Is Not Available An...
Read more >
Object has more than one person account record type default
Gearset will show a warning explaining what the problem is. However, we can't tell which record type is intended to be the default....
Read more >
How to Set a Record Type in Salesforce Object in ... - Infometry
This issue is encountered when: · Solution : · Check if there's more than one record type assigned under your profile. · Please...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found