I've encountered an issue while working with Typescript and Jest in my code testing. I tried to do a type casting on a class for mocking purposes, but it resulted in an error during the test suite run:
SyntaxError: C:\Projects\sim_editor\server\src\tests\routes.test.ts: Missing semicolon (7:37)
Below is the snippet of the code causing the problem:
describe('Unit test api routes', () => {
jest.mock('../controllers')
const mkControllers = Controllers as jest.MockedClass<typeof Controllers>
beforeEach(() => {
mkControllers.mockClear()
})
.
.
.
The remaining tests go here
})
The error message specifically mentions the "mkControllers" line.
A more detailed log of the error is shown below:
at Parser._raise (node_modules/@babel/parser/src/parser/error.js:97:45)
at Parser.raiseWithData (node_modules/@babel/parser/src/parser/error.js:92:17)
at Parser.raise (node_modules/@babel/parser/src/parser/error.js:41:17)
at Parser.semicolon (node_modules/@babel/parser/src/parser/util.js:131:10)
at Parser.parseVarStatement (node_modules/@babel/parser/src/parser/statement.js:707:10)
at Parser.parseStatementContent (node_modules/@babel/parser/src/parser/statement.js:223:21)
at Parser.parseStatement (node_modules/@babel/parser/src/parser/statement.js:163:17)
at Parser.parseBlockOrModuleBlockBody (node_modules/@babel/parser/src/parser/statement.js:880:25)
at Parser.parseBlockBody (node_modules/@babel/parser/src/parser/statement.js:856:10)
at Parser.parseBlock (node_modules/@babel/parser/src/parser/statement.js:826:10)
Your help will be greatly appreciated!