I am testing the creation of a new ticket entity with Jest in my Node/TS project. The types for a ticket are provided below:
export interface Entity {
getId: () => string;
getTitle: () => string;
}
export interface Ticket extends Entity {
getDetails: () => string;
getCategory: () => CategoryOptions;
getStatus: () => StatusOptions;
getCreatedAt: () => Date;
getUpdatedAt: () => Date;
}
As you can see, the Ticket extends the props of a generic Entity type. There are no type errors in my actual code, but inside my test suite, I am trying:
it("should create new ticket entity", () => {
const ticket: Ticket = makeTicket(ticketInfo);
expect(ticket.getId()).toBe("1234567890");
});
which outputs the following type error
Property 'getId' does not exist on type 'Ticket'. ts(2339)
Here is my babel.config.ts file:
export default {
// Stop running tests after `n` failures
bail: 3,
// Automatically clear mock calls and instances between every test
clearMocks: true,
// Indicates whether the coverage information should be collected while executing the test
collectCoverage: true,
// The directory where Jest should output its coverage files
coverageDirectory: "coverage",
// An array of regexp pattern strings used to skip coverage collection
coveragePathIgnorePatterns: [
"/node_modules/"
],
// Indicates which provider should be used to instrument code for coverage
coverageProvider: "v8",
// A list of reporter names that Jest uses when writing coverage reports
coverageReporters: [
"json",
"html",
"text"
],
// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: -10
}
},
// An array of file extensions your modules use
moduleFileExtensions: [
"js",
"ts"
],
// A preset that is used as a base for Jest's configuration
preset: "ts-jest",
// The root directory that Jest should scan for tests and modules within
rootDir: ".",
// A list of paths to directories that Jest should use to search for files in
roots: [
"<rootDir>/src"
],
// The test environment that will be used for testing
testEnvironment: "node",
// The glob patterns Jest uses to detect test files
testMatch: [
"**/__tests__/**/*.[jt]s?(x)",
"**/?(*.)+(spec|test).[tj]s?(x)"
],
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
testPathIgnorePatterns: [
"/node_modules/",
"/api/",
"/config/"
],
};
And my relevant package.json dependencies:
"devDependencies": {
"@babel/cli": "^7.13.10",
"@babel/core": "^7.13.14",
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/preset-env": "^7.13.12",
"@babel/preset-typescript": "^7.13.0",
"@types/jest": "^26.0.20",
"@types/node": "^14.14.25",
"@typescript-eslint/eslint-plugin": "^4.20.0",
"@typescript-eslint/parser": "^4.20.0",
"babel-plugin-module-resolver": "^4.1.0",
"eslint": "^7.19.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.3.6",
"jest": "^26.6.3",
"ts-jest": "^26.5.6",
"ts-node": "^9.1.1",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.1.4",
}
Any ideas on how to ensure that Jest can read the types of ancestor types?