Record type issue
See original GitHub issueGetting 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:
- Created 3 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@bigmontz looking forward to 4.3, as it’ll finally allow me to write unittests with a mocked driver.
It will be solved in the 4.3