Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
157
rated 0 times [  163] [ 6]  / answers: 1 / hits: 25946  / 3 Years ago, tue, march 2, 2021, 12:00:00

I'm using Typescript and trying to test my code with Jest, and I made a type casting on a class so I can mock it.


Unfortunately, when I ran the test suite I got the following error:


 SyntaxError: C:Projectssim_editorserversrctestsroutes.test.ts: Missing semicolon (7:37)

Here is my code:


describe('Unit test api routes', () => {
jest.mock('../controllers')
const mkControllers = Controllers as jest.MockedClass<typeof Controllers>

beforeEach(() => {
mkControllers.mockClear()
})

.
.
.
The rest of my test suite
})

The error was referring the line where I declared "mkControllers".


Here is a deeper log of the error:


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)

Thanks.


More From » typescript

 Answers
2

Apparently I didn't configure Babel to work with Typescript, as it is essential for Jest to use it.
Make sure you follow the instructions here, under "Using Babel" and "Using Typescript"


[#50373] Saturday, February 13, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kendellc

Total Points: 84
Total Questions: 97
Total Answers: 102

Location: Moldova
Member since Sat, Aug 6, 2022
2 Years ago
;