I am trying to run test case for testing entry point of my web service jest I am facing one issue while running the unit test. Cannot spy the async function, because it is a property not a function.
I am trying to test if the run function is called in the server.js file
The entry file is somewhat like below.
import config from 'config';
export default async function run() {
try {
/*
some code
*/
} catch (err) {
process.exit(1);
}
}
run();
And the test file is like below
import run from '../server';
describe('server-test', () => {
it('run', async () => {
const start = require('../server');
const spy = jest.spyOn(start, run);
await run();
expect(spy).toBeCalled();
});
});
The test should run properly, but I am getting below error on running this test
Cannot spy the async function run() {
try {
/*
some code.
*/
} catch (err) {
process.exit(1);
}
} property because it is not a function; undefined given instead