New to Jest so I'm wanting to understand an issue I'm having a bit better. I'm trying to test an implementation of a class in Jest but it's complaining that my function "is not a function"
Typescript Service:
export class TestService {
constructor() { }
getAllData = async (): Promise<any> => {
return { id: '1', name: 'test' }
}
}
Test
import { TestService } from '../TestService';
describe('TestService', async () => {
const service = new TestService();
const res = await service.getAllData();
....
}
jest.config.ts import type {Config} from '@jest/types';
const config: Config.InitialOptions = {
roots:['<rootDir>'],
testMatch: [
'**/__tests__/**/*.+(ts|tsx|js)',
'**/?(*.)+(spec|test).+(ts|tsx|js)'
],
testPathIgnorePatterns: ['dist', 'node_modules'],
transform: {"\\.(ts|tsx)$": "ts-jest"},
verbose: true,
preset: 'ts-jest',
testEnvironment: 'node',
collectCoverage: true,
automock: true
};
export default config;
When I run the tests, Jest is throwing an error that says "service.getAllData is not a function". Everything I could find online points me to mocks but I wouldn't think I would want to mock this as I want to test the actual implementation of the class; I assume I'd want to mock any external functions within getAllData().
I have a controller that is able to call this function with no problems so I'm wondering if either 1) there's some other way this must be called or 2) Jest essentially requires mocks of some kind.
Please let me know if you have any insight
Thanks!
constructor()orconstructor() { }?